Skip to content

Commit e3bd6db

Browse files
nicohrubecclaude
andcommitted
fix(browser): Use String() to stringify non-Error captureException inputs
`${exception}` throws a TypeError for Symbol inputs. Use String() instead, which safely handles Symbols while producing identical output for all other values. This was a pre-existing issue on the addExceptionTypeValue line. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5ee1271 commit e3bd6db

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

packages/browser/src/eventbuilder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,9 @@ export function eventFromUnknownInput(
334334
// - a plain Object
335335
//
336336
// So bail out and capture it as a simple message:
337-
event = eventFromString(stackParser, `${exception}`, syntheticException, attachStacktrace);
338-
addExceptionTypeValue(event, `${exception}`, undefined);
337+
const stringifiedException = String(exception);
338+
event = eventFromString(stackParser, stringifiedException, syntheticException, attachStacktrace);
339+
addExceptionTypeValue(event, stringifiedException, undefined);
339340
addExceptionMechanism(event, {
340341
synthetic: true,
341342
});

packages/browser/test/eventbuilder.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ describe('eventFromUnknownInput', () => {
182182
);
183183
});
184184

185+
it('does not throw and stringifies the value for a Symbol input', async () => {
186+
const event = await eventFromUnknownInput(defaultStackParser, Symbol('foo'));
187+
188+
expect(event.exception?.values?.[0]).toEqual(
189+
expect.objectContaining({
190+
type: 'Error',
191+
value: 'Symbol(foo)',
192+
}),
193+
);
194+
});
195+
185196
it('add a synthetic stack trace to DOMException with empty stack traces if attachStacktrace is true', async () => {
186197
const exception = new DOMException('The string did not match the expected pattern.', 'SyntaxError');
187198
exception.stack = '';

0 commit comments

Comments
 (0)