diff --git a/error-stack-parser.js b/error-stack-parser.js index 9de504a..5231091 100644 --- a/error-stack-parser.js +++ b/error-stack-parser.js @@ -56,21 +56,21 @@ return filtered.map(function(line) { if (line.indexOf('(eval ') > -1) { // Throw away eval information until we implement stacktrace.js/stackframe#8 - line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^()]*)|(\),.*$)/g, ''); + line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^()]*)|(,.*$)/g, ''); } - var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '('); + var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').replace(/^.*?\s+/, ''); // capture and preseve the parenthesized location "(/foo/my bar.js:12:87)" in // case it has spaces in it, as the string is split on \s+ later on - var location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/); + var location = sanitizedLine.match(/ (\(.+\)$)/); // remove the parenthesized location from the line, if it was matched sanitizedLine = location ? sanitizedLine.replace(location[0], '') : sanitizedLine; - var tokens = sanitizedLine.split(/\s+/).slice(1); - // if a location was matched, pass it to extractLocation() otherwise pop the last token - var locationParts = this.extractLocation(location ? location[1] : tokens.pop()); - var functionName = tokens.join(' ') || undefined; + // if a location was matched, pass it to extractLocation() otherwise pass all sanitizedLine + // because this line doesn't have function name + var locationParts = this.extractLocation(location ? location[1] : sanitizedLine); + var functionName = location && sanitizedLine || undefined; var fileName = ['eval', ''].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0]; return new StackFrame({ diff --git a/spec/error-stack-parser-spec.js b/spec/error-stack-parser-spec.js index 0244a12..8177b16 100644 --- a/spec/error-stack-parser-spec.js +++ b/spec/error-stack-parser-spec.js @@ -225,10 +225,13 @@ describe('ErrorStackParser', function() { it('should handle spaces in Node.js stacks', function() { var stackframes = unit.parse(CapturedExceptions.NODE_WITH_SPACES); - expect(stackframes.length).toBe(7); + expect(stackframes.length).toBe(8); expect(stackframes[0].fileName).toEqual('/var/app/scratch/my project/index.js'); expect(stackframes[0].lineNumber).toBe(2); expect(stackframes[0].columnNumber).toBe(9); + expect(stackframes[1].fileName).toEqual('/var/app/scratch/my project/index.js'); + expect(stackframes[1].lineNumber).toBe(2); + expect(stackframes[1].columnNumber).toBe(9); }); }); }); diff --git a/spec/fixtures/captured-errors.js b/spec/fixtures/captured-errors.js index 36c6856..f7ff703 100644 --- a/spec/fixtures/captured-errors.js +++ b/spec/fixtures/captured-errors.js @@ -387,7 +387,8 @@ CapturedExceptions.EDGE_20_NESTED_EVAL = { CapturedExceptions.NODE_WITH_SPACES = { name: 'Error', message: '', - stack: 'Error\n at Object. ' + + stack: 'Error\n at /var/app/scratch/my '+ + 'project/index.js:2:9\n at Object. ' + '(/var/app/scratch/my ' + 'project/index.js:2:9)\n at Module._compile ' + '(internal/modules/cjs/loader.js:774:30)\n at ' +