Permalink
Browse files

Parse stacks with multiline messages

  • Loading branch information...
felixge committed Jul 17, 2011
1 parent 18c04ef commit 5d4f8dfbce63da5ee59c0e53c8f9de010271ac2b
Showing with 56 additions and 37 deletions.
  1. +44 −37 lib/stack-trace.js
  2. +12 −0 test/integration/test-parse.js
View
@@ -21,46 +21,53 @@ exports.parse = function(err) {
var self = this;
var lines = err.stack.split('\n').slice(1);
- return lines.map(function(line) {
- var lineMatch = line.match(/at (?:([^\s]+)\s+)?\(?(?:(.+?):(\d+):(\d+)|([^)]+))\)?/);
-
- var object = null;
- var method = null;
- var functionName = null;
- var typeName = null;
- var methodName = null;
- var isNative = (lineMatch[5] === 'native');
-
- if (lineMatch[1]) {
- var methodMatch = lineMatch[1].match(/([^\.]+)(?:\.(.+))?/);
- object = methodMatch[1];
- method = methodMatch[2];
- functionName = lineMatch[1];
- typeName = 'Object';
- }
+ return lines
+ .map(function(line) {
+ var lineMatch = line.match(/at (?:([^\s]+)\s+)?\(?(?:(.+?):(\d+):(\d+)|([^)]+))\)?/);
+ if (!lineMatch) {
+ return;
+ }
- if (method) {
- typeName = object;
- methodName = method;
- }
+ var object = null;
+ var method = null;
+ var functionName = null;
+ var typeName = null;
+ var methodName = null;
+ var isNative = (lineMatch[5] === 'native');
+
+ if (lineMatch[1]) {
+ var methodMatch = lineMatch[1].match(/([^\.]+)(?:\.(.+))?/);
+ object = methodMatch[1];
+ method = methodMatch[2];
+ functionName = lineMatch[1];
+ typeName = 'Object';
+ }
- if (method === '<anonymous>') {
- methodName = null;
- functionName = '';
- }
+ if (method) {
+ typeName = object;
+ methodName = method;
+ }
+
+ if (method === '<anonymous>') {
+ methodName = null;
+ functionName = '';
+ }
- var properties = {
- fileName: lineMatch[2] || null,
- lineNumber: parseInt(lineMatch[3], 10) || null,
- functionName: functionName,
- typeName: typeName,
- methodName: methodName,
- columnNumber: parseInt(lineMatch[4], 10) || null,
- 'native': isNative,
- };
-
- return self._createParsedCallSite(properties);
- });
+ var properties = {
+ fileName: lineMatch[2] || null,
+ lineNumber: parseInt(lineMatch[3], 10) || null,
+ functionName: functionName,
+ typeName: typeName,
+ methodName: methodName,
+ columnNumber: parseInt(lineMatch[4], 10) || null,
+ 'native': isNative,
+ };
+
+ return self._createParsedCallSite(properties);
+ })
+ .filter(function(callSite) {
+ return !!callSite;
+ });
};
exports._createParsedCallSite = function(properties) {
@@ -100,3 +100,15 @@ var stackTrace = require(common.dir.lib + '/stack-trace');
assert.strictEqual(callSite.getColumnNumber(), 10);
assert.strictEqual(callSite.isNative(), false);
})();
+
+(function testStackWithMultilineMessage() {
+ var err = {};
+ err.stack =
+'AssertionError: true == false\nAnd some more shit\n' +
+' at /Users/felix/code/node-fast-or-slow/lib/test_case.js:80:10';
+
+ var trace = stackTrace.parse(err);
+ var callSite = trace[0];
+
+ assert.strictEqual(callSite.getFileName(), '/Users/felix/code/node-fast-or-slow/lib/test_case.js');
+})();

0 comments on commit 5d4f8df

Please sign in to comment.