Skip to content

Commit

Permalink
Added parsing support for Node.js stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
Calamari committed Feb 5, 2014
1 parent 80d7b15 commit 6737038
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# StackTrace-Parser

This parser parses a stack trace from any browser and returns an array of hashes representing a line.
This parser parses a stack trace from any browser or Node.js and returns an array of hashes representing a line.

## Usage

Expand Down
8 changes: 8 additions & 0 deletions lib/stacktrace-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var StackTraceParser = {
parse: function(stackString) {
var chrome = /^\s*at (?:(?:(?:Anonymous function)?|((?:\[object object\])?\S+(?: \[as \S+\])?)) )?\(?((?:file|http|https):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
gecko = /^(?:\s*(\S*)(?:\((.*?)\))?@)?((?:file|http|https).*?):(\d+)(?::(\d+))?\s*$/i,
node = /^\s*at (?:((?:\[object object\])?\S+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i,
lines = stackString.split('\n'),
stack = [],
parts,
Expand All @@ -30,6 +31,13 @@ var StackTraceParser = {
'lineNumber': +parts[3],
'column': parts[4] ? +parts[4] : null
};
} else if ((parts = node.exec(lines[i]))) {
element = {
'file': parts[2],
'methodName': parts[1] || UNKNOWN_FUNCTION,
'lineNumber': +parts[3],
'column': parts[4] ? +parts[4] : null
};
} else {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Georg Tavonius <g.tavonius@gmail.com> (http://jaz-lounge.com)",
"name": "stacktrace-parser",
"description": "Parses every stack trace into a nicely formatted array of hashes.",
"version": "0.1.0",
"version": "0.1.1",
"engines": {
"node": "~0.10"
},
Expand All @@ -17,6 +17,6 @@
},
"main": "index.js",
"scripts": {
"test": "make test"
"test": "./node_modules/.bin/grunt test"
}
}
36 changes: 36 additions & 0 deletions test/stacktrace_parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,42 @@ describe('StackTraceParser', function() {
lineNumber: 4,
column: 551 } ]
}
],
'Node.js': [
{
from: "ReferenceError: test is not defined\n at repl:1:2\n at REPLServer.self.eval (repl.js:110:21)\n at Interface.<anonymous> (repl.js:239:12)\n at Interface.EventEmitter.emit (events.js:95:17)\n at emitKey (readline.js:1095:12)",
to: [ { file: 'repl',
methodName: '<unknown>',
lineNumber: 1,
column: 2 },
{ file: 'repl.js',
methodName: 'REPLServer.self.eval',
lineNumber: 110,
column: 21 },
{ file: 'repl.js',
methodName: 'Interface.<anonymous>',
lineNumber: 239,
column: 12 },
{ file: 'events.js',
methodName: 'Interface.EventEmitter.emit',
lineNumber: 95,
column: 17 },
{ file: 'readline.js',
methodName: 'emitKey',
lineNumber: 1095,
column: 12 } ]
},
{
from: "ReferenceError: breakDown is not defined\n at null._onTimeout (repl:1:25)\n at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)",
to: [ { file: 'repl',
methodName: 'null._onTimeout',
lineNumber: 1,
column: 25 },
{ file: 'timers.js',
methodName: 'Timer.listOnTimeout [as ontimeout]',
lineNumber: 110,
column: 15 } ]
}
]
};

Expand Down

0 comments on commit 6737038

Please sign in to comment.