Skip to content

Commit ee4d165

Browse files
authored
fix(browser): Strip webpack wrapping from stack frames (#5522)
I did try and solve this via the Chrome regex but found that the 2nd line (`(error: https://s1.sentry-cdn.com/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js)`) was picked up by the gecko parser. This change just strips the `(error: *)` wrapper from all lines before parsing proper. Line 2 is still parsed by the gecko parser but the resulting frame seems sensible even if it doesn't contain much useful info.
1 parent f240077 commit ee4d165

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

packages/browser/test/unit/tracekit/chromium.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,54 @@ describe('Tracekit - Chrome Tests', () => {
497497
},
498498
});
499499
});
500+
501+
it('should parse webpack wrapped exceptions', () => {
502+
const EXCEPTION = {
503+
message: 'aha',
504+
name: 'ChunkLoadError',
505+
stack: `ChunkLoadError: Loading chunk app_bootstrap_initializeLocale_tsx failed.
506+
(error: https://s1.sentry-cdn.com/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js)
507+
at (error: (/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js))
508+
at key(webpack/runtime/jsonp chunk loading:27:18)
509+
at ? (webpack/runtime/ensure chunk:6:25)
510+
at Array.reduce(<anonymous>)`,
511+
};
512+
513+
const ex = exceptionFromError(parser, EXCEPTION);
514+
515+
expect(ex).toEqual({
516+
value: 'aha',
517+
type: 'ChunkLoadError',
518+
stacktrace: {
519+
frames: [
520+
{ filename: '<anonymous>', function: 'Array.reduce', in_app: true },
521+
{
522+
filename: 'webpack/runtime/ensure chunk',
523+
function: '?',
524+
in_app: true,
525+
lineno: 6,
526+
colno: 25,
527+
},
528+
{
529+
filename: 'webpack/runtime/jsonp chunk loading',
530+
function: 'key',
531+
in_app: true,
532+
lineno: 27,
533+
colno: 18,
534+
},
535+
{
536+
filename: '/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js',
537+
function: '?',
538+
in_app: true,
539+
},
540+
{
541+
filename:
542+
'https://s1.sentry-cdn.com/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js',
543+
function: '?',
544+
in_app: true,
545+
},
546+
],
547+
},
548+
});
549+
});
500550
});

packages/utils/src/stacktrace.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser {
1616
const frames: StackFrame[] = [];
1717

1818
for (const line of stack.split('\n').slice(skipFirst)) {
19+
// https://github.com/getsentry/sentry-javascript/issues/5459
20+
// Remove webpack (error: *) wrappers
21+
const cleanedLine = line.replace(/\(error: (.*)\)/, '$1');
22+
1923
for (const parser of sortedParsers) {
20-
const frame = parser(line);
24+
const frame = parser(cleanedLine);
2125

2226
if (frame) {
2327
frames.push(frame);

0 commit comments

Comments
 (0)