Skip to content

feat(browser): Add DOMException.code as tag if it exists #3018

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

Merged
merged 2 commits into from
Nov 4, 2020

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Oct 29, 2020

Though DOMException.code is long since deprecated in favor of DOMException.name, there are apparently still cases where it shows up. This adds the code as a tag in those cases.

Fixes #3005.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 29, 2020

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 19.72 KB (0%)
@sentry/browser - Webpack 20.58 KB (0%)
@sentry/react - Webpack 20.58 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 26.86 KB (+0.01% 🔺)

@lobsterkatie lobsterkatie force-pushed the kmclb-add-code-to-domexception branch from d7839ce to 18277ed Compare October 29, 2020 17:35
@lobsterkatie lobsterkatie changed the title feat(browser): Add DOMException.code to event message if .name is undefined feat(browser): Add DOMException.code as tag if it exists Oct 29, 2020
@@ -87,6 +87,8 @@ export function eventFromUnknownInput(

event = eventFromString(message, syntheticException, options);
addExceptionTypeValue(event, message);
event.tags = domException.code ? { ...event.tags, 'DOMException.code': String(domException.code) } : event.tags;
Copy link
Contributor

@kamilogorek kamilogorek Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventFromString has no way to add any tags to the event itself, so this fallback will always produce an event with malformed tags:

const event = {}
console.log(event) // {}
event.tags = event.tags
console.log(event) // {tags:undefined}

Also code can be 0 for some custom types, which will omit this, as they are using integers, not strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch. Thanks.

@@ -87,6 +87,8 @@ export function eventFromUnknownInput(

event = eventFromString(message, syntheticException, options);
addExceptionTypeValue(event, message);
event.tags = domException.code ? { ...event.tags, 'DOMException.code': String(domException.code) } : event.tags;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
event.tags = domException.code ? { ...event.tags, 'DOMException.code': String(domException.code) } : event.tags;
if ('code' in domException) {
event.tags = { ...event.tags, 'DOMException.code': `${domException.code}` }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the "old" tags, just in case we ever decided to for example mark events as being produced by eventFromString or something. Keep in mind that its safe to destructure undefined values, see:
https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md

Null/Undefined Are Ignored

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm confused. I did, too...

@kamilogorek kamilogorek merged commit a3fb285 into master Nov 4, 2020
@kamilogorek kamilogorek deleted the kmclb-add-code-to-domexception branch November 4, 2020 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing error.code on uncaught exceptions
3 participants