Skip to content

Commit ce8d8f8

Browse files
authored
fix(node): Handle colons in stack trace paths (#5517)
Update the node parser regex to handle colons in stacktraces. This change also drops the ability to parse stack frames that don't have column numbers. Modern versions of v8/node always have column numbers.
1 parent 474a0a0 commit ce8d8f8

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

packages/node/test/stacktrace.test.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -120,33 +120,6 @@ describe('Stack parsing', () => {
120120
]);
121121
});
122122

123-
test('parses with missing column numbers', () => {
124-
const err = new Error();
125-
err.stack =
126-
'AssertionError: true == false\n' +
127-
' at Test.fn (/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js:6)\n' +
128-
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/test.js:45)';
129-
130-
const frames = parseStackFrames(stackParser, err);
131-
132-
expect(frames).toEqual([
133-
{
134-
filename: '/Users/felix/code/node-fast-or-slow/lib/test.js',
135-
module: 'test',
136-
function: 'Test.run',
137-
lineno: 45,
138-
in_app: true,
139-
},
140-
{
141-
filename: '/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js',
142-
module: 'test-example',
143-
function: 'Test.fn',
144-
lineno: 6,
145-
in_app: true,
146-
},
147-
]);
148-
});
149-
150123
test('parses with native methods', () => {
151124
const err = new Error();
152125
err.stack =
@@ -379,4 +352,33 @@ describe('Stack parsing', () => {
379352
},
380353
]);
381354
});
355+
356+
test('parses with colons in paths', () => {
357+
const err = new Error();
358+
err.stack =
359+
'AssertionError: true == false\n' +
360+
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/20:20:20/test.js:45:10)\n' +
361+
' at TestCase.run (/Users/felix/code/node-fast-or-slow/lib/test_case.js:61:8)\n';
362+
363+
const frames = parseStackFrames(stackParser, err);
364+
365+
expect(frames).toEqual([
366+
{
367+
filename: '/Users/felix/code/node-fast-or-slow/lib/test_case.js',
368+
module: 'test_case',
369+
function: 'TestCase.run',
370+
lineno: 61,
371+
colno: 8,
372+
in_app: true,
373+
},
374+
{
375+
filename: '/Users/felix/code/node-fast-or-slow/lib/20:20:20/test.js',
376+
module: 'test',
377+
function: 'Test.run',
378+
lineno: 45,
379+
colno: 10,
380+
in_app: true,
381+
},
382+
]);
383+
});
382384
});

packages/utils/src/stacktrace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type GetModuleFn = (filename: string | undefined) => string | undefined;
100100
// eslint-disable-next-line complexity
101101
function node(getModule?: GetModuleFn): StackLineParserFn {
102102
const FILENAME_MATCH = /^\s*[-]{4,}$/;
103-
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/;
103+
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;
104104

105105
// eslint-disable-next-line complexity
106106
return (line: string) => {

0 commit comments

Comments
 (0)