Skip to content

Commit

Permalink
fix(node): Handle colons in stack trace paths (#5517)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timfish authored Aug 3, 2022
1 parent 474a0a0 commit ce8d8f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
56 changes: 29 additions & 27 deletions packages/node/test/stacktrace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,6 @@ describe('Stack parsing', () => {
]);
});

test('parses with missing column numbers', () => {
const err = new Error();
err.stack =
'AssertionError: true == false\n' +
' at Test.fn (/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js:6)\n' +
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/test.js:45)';

const frames = parseStackFrames(stackParser, err);

expect(frames).toEqual([
{
filename: '/Users/felix/code/node-fast-or-slow/lib/test.js',
module: 'test',
function: 'Test.run',
lineno: 45,
in_app: true,
},
{
filename: '/Users/felix/code/node-fast-or-slow/test/fast/example/test-example.js',
module: 'test-example',
function: 'Test.fn',
lineno: 6,
in_app: true,
},
]);
});

test('parses with native methods', () => {
const err = new Error();
err.stack =
Expand Down Expand Up @@ -379,4 +352,33 @@ describe('Stack parsing', () => {
},
]);
});

test('parses with colons in paths', () => {
const err = new Error();
err.stack =
'AssertionError: true == false\n' +
' at Test.run (/Users/felix/code/node-fast-or-slow/lib/20:20:20/test.js:45:10)\n' +
' at TestCase.run (/Users/felix/code/node-fast-or-slow/lib/test_case.js:61:8)\n';

const frames = parseStackFrames(stackParser, err);

expect(frames).toEqual([
{
filename: '/Users/felix/code/node-fast-or-slow/lib/test_case.js',
module: 'test_case',
function: 'TestCase.run',
lineno: 61,
colno: 8,
in_app: true,
},
{
filename: '/Users/felix/code/node-fast-or-slow/lib/20:20:20/test.js',
module: 'test',
function: 'Test.run',
lineno: 45,
colno: 10,
in_app: true,
},
]);
});
});
2 changes: 1 addition & 1 deletion packages/utils/src/stacktrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type GetModuleFn = (filename: string | undefined) => string | undefined;
// eslint-disable-next-line complexity
function node(getModule?: GetModuleFn): StackLineParserFn {
const FILENAME_MATCH = /^\s*[-]{4,}$/;
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/;
const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;

// eslint-disable-next-line complexity
return (line: string) => {
Expand Down

0 comments on commit ce8d8f8

Please sign in to comment.