-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): Be stricter about mechanism values
#4068
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
Changes from all commits
f4418ae
c49257c
ea2e822
01187b4
ebde5d4
0f7d6a0
707eb5d
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 |
|---|---|---|
|
|
@@ -390,6 +390,7 @@ describe('AWSLambda', () => { | |
| { | ||
| mechanism: { | ||
| handled: false, | ||
| type: 'generic', | ||
| }, | ||
| }, | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -458,6 +458,7 @@ describe('GCPFunction', () => { | |
| { | ||
| mechanism: { | ||
| handled: false, | ||
| type: 'generic', | ||
| }, | ||
| }, | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,32 @@ | ||
| /** JSDoc */ | ||
| /** | ||
| * Metadata about a captured exception, intended to provide a hint as to the means by which it was captured. | ||
| */ | ||
| export interface Mechanism { | ||
| /** | ||
| * For now, restricted to `onerror`, `onunhandledrejection` (both obvious), `instrument` (the result of | ||
| * auto-instrumentation), and `generic` (everything else). Converted to a tag on ingest. | ||
| */ | ||
| type: string; | ||
|
|
||
| /** | ||
| * In theory, whether or not the exception has been handled by the user. In practice, whether or not we see it before | ||
| * it hits the global error/rejection handlers, whether through explicit handling by the user or auto instrumentation. | ||
| * Converted to a tag on ingest and used in various ways in the UI. | ||
| */ | ||
| handled: boolean; | ||
|
|
||
| /** | ||
| * Arbitrary data to be associated with the mechanism (for example, errors coming from event handlers include the | ||
| * handler name and the event target. Will show up in the UI directly above the stacktrace. | ||
| */ | ||
| data?: { | ||
| [key: string]: string | boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * True when `captureException` is called with anything other than an instance of `Error` (or, in the case of browser, | ||
| * an instance of `ErrorEvent`, `DOMError`, or `DOMException`). causing us to create a synthetic error in an attempt | ||
| * to recreate the stacktrace. | ||
| */ | ||
| synthetic?: boolean; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import { Event, StackFrame } from '@sentry/types'; | ||
| import { Event, Mechanism, StackFrame } from '@sentry/types'; | ||
|
|
||
| import { getGlobalObject } from './global'; | ||
| import { snipLine } from './string'; | ||
|
|
@@ -125,29 +125,25 @@ export function addExceptionTypeValue(event: Event, value?: string, type?: strin | |
| } | ||
|
|
||
| /** | ||
| * Adds exception mechanism to a given event. | ||
| * Adds exception mechanism data to a given event. Uses defaults if the second parameter is not passed. | ||
| * | ||
| * @param event The event to modify. | ||
| * @param mechanism Mechanism of the mechanism. | ||
| * @param newMechanism Mechanism data to add to the event. | ||
| * @hidden | ||
| */ | ||
| export function addExceptionMechanism( | ||
| event: Event, | ||
| mechanism: { | ||
| [key: string]: any; | ||
| } = {}, | ||
| ): void { | ||
| // TODO: Use real type with `keyof Mechanism` thingy and maybe make it better? | ||
| try { | ||
| // @ts-ignore Type 'Mechanism | {}' is not assignable to type 'Mechanism | undefined' | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| event.exception!.values![0].mechanism = event.exception!.values![0].mechanism || {}; | ||
| Object.keys(mechanism).forEach(key => { | ||
| // @ts-ignore Mechanism has no index signature | ||
| // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
| event.exception!.values![0].mechanism[key] = mechanism[key]; | ||
| }); | ||
| } catch (_oO) { | ||
| // no-empty | ||
| export function addExceptionMechanism(event: Event, newMechanism?: Partial<Mechanism>): void { | ||
| if (!event.exception || !event.exception.values) { | ||
| return; | ||
| } | ||
| const exceptionValue0 = event.exception.values[0]; | ||
|
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. feels weird this just updates the first exception.
Member
Author
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. To be fair, that's what the function it's replacing did, also (which is reflective of the fact that 99.9% of the time, there is only one exception). But it's a fair point. That said, it's not obvious to me what the correct fix would be, because I've seen so few examples of there being multiple exceptions. Would they always be caught by the same mechanism (in which case we can just loop) or might the values be different (in which case we'd need to get more complicated and specify which one we're talking about)? TBH, I'm not even 100% sure what could ever cause there to be more than one... In any case, happy to discuss it but am not going to block on it. |
||
|
|
||
| const defaultMechanism = { type: 'generic', handled: true }; | ||
| const currentMechanism = exceptionValue0.mechanism; | ||
| exceptionValue0.mechanism = { ...defaultMechanism, ...currentMechanism, ...newMechanism }; | ||
|
|
||
| if (newMechanism && 'data' in newMechanism) { | ||
lobsterkatie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const mergedData = { ...currentMechanism?.data, ...newMechanism.data }; | ||
| exceptionValue0.mechanism.data = mergedData; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.