diff --git a/README.md b/README.md index 85ce464..ce808ea 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/stacktrace-parser.js b/lib/stacktrace-parser.js index 0baaf3e..6698638 100644 --- a/lib/stacktrace-parser.js +++ b/lib/stacktrace-parser.js @@ -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, @@ -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; } diff --git a/package.json b/package.json index fc7b4f9..e7e92b1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Georg Tavonius (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" }, @@ -17,6 +17,6 @@ }, "main": "index.js", "scripts": { - "test": "make test" + "test": "./node_modules/.bin/grunt test" } } diff --git a/test/stacktrace_parser_test.js b/test/stacktrace_parser_test.js index be06514..8a43680 100644 --- a/test/stacktrace_parser_test.js +++ b/test/stacktrace_parser_test.js @@ -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. (repl.js:239:12)\n at Interface.EventEmitter.emit (events.js:95:17)\n at emitKey (readline.js:1095:12)", + to: [ { file: 'repl', + methodName: '', + lineNumber: 1, + column: 2 }, + { file: 'repl.js', + methodName: 'REPLServer.self.eval', + lineNumber: 110, + column: 21 }, + { file: 'repl.js', + methodName: 'Interface.', + 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 } ] + } ] };