Skip to content

Commit 2e79587

Browse files
committed
fix(browser): Keep error grouping
1 parent 901e3ef commit 2e79587

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

packages/browser/src/eventbuilder.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,17 @@ export function eventFromUnknownInput(
288288
if (isDOMError(exception) || isDOMException(exception as DOMException)) {
289289
const domException = exception as DOMException;
290290

291-
if ((exception as Error).stack) {
291+
if ('stack' in (exception as Error)) {
292292
event = eventFromError(stackParser, exception as Error);
293+
294+
const firstException = event.exception?.values?.[0];
295+
if (attachStacktrace && syntheticException && firstException && !firstException.stacktrace) {
296+
const frames = parseStackFrames(stackParser, syntheticException);
297+
if (frames.length) {
298+
firstException.stacktrace = { frames };
299+
addExceptionMechanism(event, { synthetic: true });
300+
}
301+
}
293302
} else {
294303
const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
295304
const message = domException.message ? `${name}: ${domException.message}` : name;

packages/browser/test/eventbuilder.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ describe('eventFromUnknownInput', () => {
181181
stacktrace: {
182182
frames: expect.arrayContaining([expect.any(Object), expect.any(Object)]),
183183
},
184-
type: 'Error',
185-
value: 'SyntaxError: The string did not match the expected pattern.',
184+
type: 'SyntaxError',
185+
value: 'The string did not match the expected pattern.',
186186
}),
187187
);
188188
});
@@ -224,8 +224,8 @@ describe('eventFromUnknownInput', () => {
224224
const syntheticException = new Error('Test message');
225225
const event = await eventFromUnknownInput(defaultStackParser, exception, syntheticException, false);
226226
expect(event.exception?.values?.[0]).toEqual({
227-
type: 'Error',
228-
value: 'SyntaxError: The string did not match the expected pattern.',
227+
type: 'SyntaxError',
228+
value: 'The string did not match the expected pattern.',
229229
});
230230
});
231231

0 commit comments

Comments
 (0)