Skip to content

Commit a64ef83

Browse files
committed
Use traceParser as a backend for Stacktrace.parse().
1 parent d5d7e22 commit a64ef83

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

lib/stacktrace.coffee

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
jsSHA = require 'jssha'
2+
traceParser = null
23

34
PREFIX = 'stacktrace://trace'
45

@@ -33,12 +34,13 @@ class Stacktrace
3334
unregister: ->
3435
delete REGISTRY[@getUrl()]
3536

37+
# Public: Parse zero to many Stacktrace instances from a corpus of text.
38+
#
39+
# text - A raw blob of text.
40+
#
3641
@parse: (text) ->
37-
frames = []
38-
for rawLine in text.split(/\r?\n/)
39-
f = parseRubyFrame(rawLine)
40-
frames.push f if f?
41-
new Stacktrace(frames, frames[0].message)
42+
{traceParser} = require('./trace-parser') unless traceParser?
43+
traceParser(text)
4244

4345
# Internal: Return a registered trace, or null if none match the provided
4446
# URL.
@@ -55,23 +57,6 @@ class Frame
5557

5658
constructor: (@rawLine, @path, @lineNumber, @functionName) ->
5759

58-
59-
# Internal: Parse a Ruby stack frame. This is a simple placeholder until I
60-
# put together a class hierarchy to handle frame recognition and parsing.
61-
#
62-
parseRubyFrame = (rawLine) ->
63-
m = rawLine.trim().match /// ^
64-
(?:from \s+)? # On all lines but the first
65-
([^:]+) : # File path
66-
(\d+) : # Line number
67-
in \s* ` ([^']+) ' # Function name
68-
(?: : \s (.*))? # Error message, only on the first
69-
///
70-
71-
if m?
72-
[raw, path, lineNumber, functionName, message] = m
73-
new Frame(raw, path, lineNumber, functionName, message)
74-
7560
module.exports =
7661
PREFIX: PREFIX
7762
Stacktrace: Stacktrace

lib/trace-parser.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{Stacktrace, Frame} = require './stacktrace'
2+
util = require 'util'
23
fs = require 'fs'
34
path = require 'path'
4-
util = require 'util'
55

66
# Internal: Build a Frame instance with a simple DSL.
77
#

spec/parsers/ruby-trace-parser-spec.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
rubyTracer = require '../../lib/parsers/ruby-trace-parser'
33
ts = require '../trace-fixtures'
44

5-
describe 'rubyTraceParser', ->
5+
describe 'rubyTracer', ->
66
describe 'recognition', ->
77

88
it 'parses a trace from each Ruby fixture', ->

spec/stacktrace-spec.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe 'Stacktrace', ->
66
[trace, checksum] = []
77

88
beforeEach ->
9-
trace = Stacktrace.parse(TRACE)
9+
[trace] = Stacktrace.parse(TRACE)
1010
checksum = '9528763b5ab8ef052e2400e39d0f32dbe59ffcd06f039adc487f4f956511691f'
1111

1212
describe 'preparation', ->

0 commit comments

Comments
 (0)