Skip to content

Commit

Permalink
fix(browser): Strip webpack wrapping from stack frames (#5522)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timfish committed Aug 4, 2022
1 parent f240077 commit ee4d165
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
50 changes: 50 additions & 0 deletions packages/browser/test/unit/tracekit/chromium.test.ts
Expand Up @@ -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(<anonymous>)`,
};

const ex = exceptionFromError(parser, EXCEPTION);

expect(ex).toEqual({
value: 'aha',
type: 'ChunkLoadError',
stacktrace: {
frames: [
{ filename: '<anonymous>', 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,
},
],
},
});
});
});
6 changes: 5 additions & 1 deletion packages/utils/src/stacktrace.ts
Expand Up @@ -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);
Expand Down

0 comments on commit ee4d165

Please sign in to comment.