|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | | -import { Event, Integration, StackFrame, WrappedFunction } from '@sentry/types'; |
| 2 | +import { Event, Integration, Mechanism, StackFrame, WrappedFunction } from '@sentry/types'; |
3 | 3 |
|
4 | 4 | import { isNodeEnv } from './node'; |
5 | 5 | import { snipLine } from './string'; |
@@ -197,30 +197,21 @@ export function addExceptionTypeValue(event: Event, value?: string, type?: strin |
197 | 197 | } |
198 | 198 |
|
199 | 199 | /** |
200 | | - * Adds exception mechanism to a given event. |
| 200 | + * Adds exception mechanism data to a given event. |
201 | 201 | * @param event The event to modify. |
202 | | - * @param mechanism Mechanism of the mechanism. |
| 202 | + * @param newMechanism Mechanism data to add to the event. |
203 | 203 | * @hidden |
204 | 204 | */ |
205 | | -export function addExceptionMechanism( |
206 | | - event: Event, |
207 | | - mechanism: { |
208 | | - [key: string]: any; |
209 | | - } = {}, |
210 | | -): void { |
211 | | - // TODO: Use real type with `keyof Mechanism` thingy and maybe make it better? |
212 | | - try { |
213 | | - // @ts-ignore Type 'Mechanism | {}' is not assignable to type 'Mechanism | undefined' |
214 | | - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
215 | | - event.exception!.values![0].mechanism = event.exception!.values![0].mechanism || {}; |
216 | | - Object.keys(mechanism).forEach(key => { |
217 | | - // @ts-ignore Mechanism has no index signature |
218 | | - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
219 | | - event.exception!.values![0].mechanism[key] = mechanism[key]; |
220 | | - }); |
221 | | - } catch (_oO) { |
222 | | - // no-empty |
| 205 | +export function addExceptionMechanism(event: Event, newMechanism: Partial<Mechanism>): void { |
| 206 | + if (!event.exception || !event.exception.values) { |
| 207 | + return; |
223 | 208 | } |
| 209 | + const exceptionValue0 = event.exception.values[0]; |
| 210 | + |
| 211 | + const defaultMechanism = { type: 'generic', handled: true }; |
| 212 | + const currentMechanism = exceptionValue0.mechanism; |
| 213 | + const mergedData = { ...currentMechanism?.data, ...newMechanism.data }; |
| 214 | + exceptionValue0.mechanism = { ...defaultMechanism, ...currentMechanism, ...newMechanism, data: mergedData }; |
224 | 215 | } |
225 | 216 |
|
226 | 217 | /** |
|
0 commit comments