diff --git a/packages/browser/test/unit/tracekit/chromium.test.ts b/packages/browser/test/unit/tracekit/chromium.test.ts index eb1f5468e4cc..557871f34104 100644 --- a/packages/browser/test/unit/tracekit/chromium.test.ts +++ b/packages/browser/test/unit/tracekit/chromium.test.ts @@ -497,4 +497,54 @@ describe('Tracekit - Chrome Tests', () => { }, }); }); + + it('should parse webpack wrapped exceptions', () => { + const EXCEPTION = { + message: 'aha', + name: 'ChunkLoadError', + stack: `ChunkLoadError: Loading chunk app_bootstrap_initializeLocale_tsx failed. + (error: https://s1.sentry-cdn.com/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js) + at (error: (/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js)) + at key(webpack/runtime/jsonp chunk loading:27:18) + at ? (webpack/runtime/ensure chunk:6:25) + at Array.reduce()`, + }; + + const ex = exceptionFromError(parser, EXCEPTION); + + expect(ex).toEqual({ + value: 'aha', + type: 'ChunkLoadError', + stacktrace: { + frames: [ + { filename: '', function: 'Array.reduce', in_app: true }, + { + filename: 'webpack/runtime/ensure chunk', + function: '?', + in_app: true, + lineno: 6, + colno: 25, + }, + { + filename: 'webpack/runtime/jsonp chunk loading', + function: 'key', + in_app: true, + lineno: 27, + colno: 18, + }, + { + filename: '/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js', + function: '?', + in_app: true, + }, + { + filename: + 'https://s1.sentry-cdn.com/_static/dist/sentry/chunks/app_bootstrap_initializeLocale_tsx.abcdefg.js', + function: '?', + in_app: true, + }, + ], + }, + }); + }); }); diff --git a/packages/utils/src/stacktrace.ts b/packages/utils/src/stacktrace.ts index 5c183b71a568..87e27aa750cd 100644 --- a/packages/utils/src/stacktrace.ts +++ b/packages/utils/src/stacktrace.ts @@ -16,8 +16,12 @@ export function createStackParser(...parsers: StackLineParser[]): StackParser { const frames: StackFrame[] = []; for (const line of stack.split('\n').slice(skipFirst)) { + // https://github.com/getsentry/sentry-javascript/issues/5459 + // Remove webpack (error: *) wrappers + const cleanedLine = line.replace(/\(error: (.*)\)/, '$1'); + for (const parser of sortedParsers) { - const frame = parser(line); + const frame = parser(cleanedLine); if (frame) { frames.push(frame);