Skip to content

Commit e0c3229

Browse files
author
Luca Forstner
authored
fix(node): Mark stack frames with url protocol as in-app frames (#8008)
1 parent 02e1c1a commit e0c3229

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/utils/src/node-stack-trace.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ export function node(getModule?: GetModuleFn): StackLineParserFn {
8585
}
8686

8787
const isInternal =
88-
isNative || (filename && !filename.startsWith('/') && !filename.startsWith('.') && !filename.includes(':\\'));
88+
isNative ||
89+
(filename &&
90+
// It's not internal if it's an absolute linux path
91+
!filename.startsWith('/') &&
92+
// It's not internal if it's an absolute windows path
93+
!filename.includes(':\\') &&
94+
// It's not internal if the path is starting with a dot
95+
!filename.startsWith('.') &&
96+
// It's not internal if the frame has a protocol. In node, this is usually the case if the file got pre-processed with a bundler like webpack
97+
!filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//)); // Schema from: https://stackoverflow.com/a/3641782
8998

9099
// in_app is all that's not an internal Node function or a module within node_modules
91100
// note that isNative appears to return true even for node core libraries

packages/utils/test/stacktrace.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,10 @@ describe('node', () => {
264264
in_app: true,
265265
});
266266
});
267+
268+
it('should mark frames with protocols as in_app: true', () => {
269+
const line = 'at Object.<anonymous> (app:///_next/server/pages/[error].js:10:20)';
270+
const result = node(line);
271+
expect(result?.in_app).toBe(true);
272+
});
267273
});

0 commit comments

Comments
 (0)