Skip to content

Commit 1c9261a

Browse files
authored
Merge pull request #66 from Aleksey28/parse-file-name-for-node
fix: fixed parsing for node
2 parents 802ff4e + 2bd8aa1 commit 1c9261a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

error-stack-parser.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@
5656
return filtered.map(function(line) {
5757
if (line.indexOf('(eval ') > -1) {
5858
// Throw away eval information until we implement stacktrace.js/stackframe#8
59-
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^()]*)|(\),.*$)/g, '');
59+
line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^()]*)|(,.*$)/g, '');
6060
}
61-
var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(');
61+
var sanitizedLine = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').replace(/^.*?\s+/, '');
6262

6363
// capture and preseve the parenthesized location "(/foo/my bar.js:12:87)" in
6464
// case it has spaces in it, as the string is split on \s+ later on
65-
var location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
65+
var location = sanitizedLine.match(/ (\(.+\)$)/);
6666

6767
// remove the parenthesized location from the line, if it was matched
6868
sanitizedLine = location ? sanitizedLine.replace(location[0], '') : sanitizedLine;
6969

70-
var tokens = sanitizedLine.split(/\s+/).slice(1);
71-
// if a location was matched, pass it to extractLocation() otherwise pop the last token
72-
var locationParts = this.extractLocation(location ? location[1] : tokens.pop());
73-
var functionName = tokens.join(' ') || undefined;
70+
// if a location was matched, pass it to extractLocation() otherwise pass all sanitizedLine
71+
// because this line doesn't have function name
72+
var locationParts = this.extractLocation(location ? location[1] : sanitizedLine);
73+
var functionName = location && sanitizedLine || undefined;
7474
var fileName = ['eval', '<anonymous>'].indexOf(locationParts[0]) > -1 ? undefined : locationParts[0];
7575

7676
return new StackFrame({

spec/error-stack-parser-spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ describe('ErrorStackParser', function() {
225225

226226
it('should handle spaces in Node.js stacks', function() {
227227
var stackframes = unit.parse(CapturedExceptions.NODE_WITH_SPACES);
228-
expect(stackframes.length).toBe(7);
228+
expect(stackframes.length).toBe(8);
229229
expect(stackframes[0].fileName).toEqual('/var/app/scratch/my project/index.js');
230230
expect(stackframes[0].lineNumber).toBe(2);
231231
expect(stackframes[0].columnNumber).toBe(9);
232+
expect(stackframes[1].fileName).toEqual('/var/app/scratch/my project/index.js');
233+
expect(stackframes[1].lineNumber).toBe(2);
234+
expect(stackframes[1].columnNumber).toBe(9);
232235
});
233236
});
234237
});

spec/fixtures/captured-errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ CapturedExceptions.EDGE_20_NESTED_EVAL = {
387387
CapturedExceptions.NODE_WITH_SPACES = {
388388
name: 'Error',
389389
message: '',
390-
stack: 'Error\n at Object.<anonymous> ' +
390+
stack: 'Error\n at /var/app/scratch/my '+
391+
'project/index.js:2:9\n at Object.<anonymous> ' +
391392
'(/var/app/scratch/my ' +
392393
'project/index.js:2:9)\n at Module._compile ' +
393394
'(internal/modules/cjs/loader.js:774:30)\n at ' +

0 commit comments

Comments
 (0)