-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(browser): Add a synthetic stack trace to DOMException with empty stack traces if attachStacktrace is true #19988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
029e8ff
c26f7a3
6503544
83ae1e5
901e3ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,7 +288,7 @@ export function eventFromUnknownInput( | |
| if (isDOMError(exception) || isDOMException(exception as DOMException)) { | ||
| const domException = exception as DOMException; | ||
|
|
||
| if ('stack' in (exception as Error)) { | ||
| if ((exception as Error).stack) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DOMException type classification lost for empty stack tracesMedium Severity Changing the check from Additional Locations (1)Reviewed by Cursor Bugbot for commit 901e3ef. Configure here. |
||
| event = eventFromError(stackParser, exception as Error); | ||
| } else { | ||
| const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException'); | ||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,91 @@ | |
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('add a synthetic stack trace to DOMException with empty stack traces if attachStacktrace is true', async () => { | ||
| const exception = new DOMException('The string did not match the expected pattern.', 'SyntaxError'); | ||
| exception.stack = ''; | ||
|
|
||
| const syntheticException = new Error('Test message'); | ||
| const event = await eventFromUnknownInput(defaultStackParser, exception, syntheticException, true); | ||
| expect(event.exception?.values?.[0]).toEqual( | ||
| expect.objectContaining({ | ||
| mechanism: { handled: true, synthetic: true, type: 'generic' }, | ||
| stacktrace: { | ||
| frames: expect.arrayContaining([expect.any(Object), expect.any(Object)]), | ||
| }, | ||
| type: 'Error', | ||
| value: 'SyntaxError: The string did not match the expected pattern.', | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('preserves DOMException type when stack is an empty string', () => { | ||
| const exception = new DOMException('The string did not match the expected pattern.', 'SyntaxError'); | ||
| exception.stack = ''; | ||
|
|
||
| const event = eventFromUnknownInput(defaultStackParser, exception, new Error('synthetic'), true); | ||
|
|
||
| expect(event.exception?.values?.[0]).toMatchObject({ | ||
|
Check failure on line 196 in packages/browser/test/eventbuilder.test.ts
|
||
| type: 'SyntaxError', | ||
| value: 'The string did not match the expected pattern.', | ||
| }); | ||
| }); | ||
|
sentry[bot] marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contradictory test expects wrong branch behaviorMedium Severity The test "preserves DOMException type when stack is an empty string" expects Additional Locations (1)Reviewed by Cursor Bugbot for commit 83ae1e5. Configure here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works against today's implementation, I'm just ensuring we lock it in and see if this PR changes it. |
||
|
|
||
| it('add a synthetic stack trace to DOMException without a stack traces property if attachStacktrace is true', async () => { | ||
| const exception = new DOMException('The string did not match the expected pattern.', 'SyntaxError'); | ||
| delete exception.stack; | ||
|
|
||
| const syntheticException = new Error('Test message'); | ||
| const event = await eventFromUnknownInput(defaultStackParser, exception, syntheticException, true); | ||
| expect(event.exception?.values?.[0]).toEqual( | ||
| expect.objectContaining({ | ||
| mechanism: { handled: true, synthetic: true, type: 'generic' }, | ||
| stacktrace: { | ||
| frames: expect.arrayContaining([expect.any(Object), expect.any(Object)]), | ||
| }, | ||
| type: 'Error', | ||
| value: 'SyntaxError: The string did not match the expected pattern.', | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("doesn't add a synthetic stack trace to DOMException with empty stack traces if attachStacktrace is false", async () => { | ||
| const exception = new DOMException('The string did not match the expected pattern.', 'SyntaxError'); | ||
| exception.stack = ''; | ||
|
|
||
| const syntheticException = new Error('Test message'); | ||
| const event = await eventFromUnknownInput(defaultStackParser, exception, syntheticException, false); | ||
| expect(event.exception?.values?.[0]).toEqual({ | ||
| type: 'Error', | ||
| value: 'SyntaxError: The string did not match the expected pattern.', | ||
| }); | ||
| }); | ||
|
|
||
| it("doesn't add a synthetic stack trace to DOMException with stack traces if attachStacktrace is true", async () => { | ||
| const exception = new DOMException('The string did not match the expected pattern.', 'SyntaxError'); | ||
| exception.stack = 'SyntaxError\n at <anonymous>:1:2'; | ||
|
|
||
| const syntheticException = new Error('Test message'); | ||
| const event = await eventFromUnknownInput(defaultStackParser, exception, syntheticException, true); | ||
| expect(event.exception?.values?.[0]).toEqual( | ||
| expect.objectContaining({ | ||
| stacktrace: { | ||
| frames: [ | ||
| { | ||
| colno: 2, | ||
| filename: '<anonymous>', | ||
| function: '?', | ||
| in_app: true, | ||
| lineno: 1, | ||
| }, | ||
| ], | ||
| }, | ||
| type: 'SyntaxError', | ||
| value: 'The string did not match the expected pattern.', | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extractMessage', () => { | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h: I think this will change how the dom exceptions are classified, I pushed a test to see if it would pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this would keep the best of both worlds here, could you try something like: