|
1 | | -import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core'; |
2 | | -import type { Event, EventHint, Exception, ExtendedError, Integration, StackParser } from '@sentry/types'; |
3 | | -import { isInstanceOf } from '@sentry/utils'; |
| 1 | +import type { Event, EventHint, EventProcessor, ExtendedError, Hub, Integration, StackParser } from '@sentry/types'; |
| 2 | +import { aggreagateExceptionsFromError, isInstanceOf } from '@sentry/utils'; |
4 | 3 |
|
5 | 4 | import { exceptionFromError } from '../eventbuilder'; |
6 | 5 | import { ContextLines } from './contextlines'; |
@@ -41,7 +40,7 @@ export class LinkedErrors implements Integration { |
41 | 40 | /** |
42 | 41 | * @inheritDoc |
43 | 42 | */ |
44 | | - public setupOnce(): void { |
| 43 | + public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void { |
45 | 44 | addGlobalEventProcessor(async (event: Event, hint: EventHint) => { |
46 | 45 | const hub = getCurrentHub(); |
47 | 46 | const self = hub.getIntegration(LinkedErrors); |
@@ -69,26 +68,16 @@ export class LinkedErrors implements Integration { |
69 | 68 | return event; |
70 | 69 | } |
71 | 70 |
|
72 | | - const linkedErrors = this._walkErrorTree(stackParser, hint.originalException as ExtendedError, this._key); |
73 | | - event.exception.values = [...linkedErrors, ...event.exception.values]; |
74 | | - return event; |
75 | | - } |
76 | | - |
77 | | - /** |
78 | | - * @inheritDoc |
79 | | - */ |
80 | | - private _walkErrorTree( |
81 | | - stackParser: StackParser, |
82 | | - error: ExtendedError, |
83 | | - key: string, |
84 | | - stack: Exception[] = [], |
85 | | - ): Exception[] { |
86 | | - if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) { |
87 | | - return stack; |
88 | | - } |
| 71 | + const linkedErrors = aggreagateExceptionsFromError( |
| 72 | + exceptionFromError, |
| 73 | + stackParser, |
| 74 | + this._limit, |
| 75 | + hint.originalException as ExtendedError, |
| 76 | + this._key, |
| 77 | + ); |
89 | 78 |
|
90 | | - const exception = exceptionFromError(stackParser, error[key]); |
| 79 | + event.exception.values = [...linkedErrors, ...event.exception.values]; |
91 | 80 |
|
92 | | - return this._walkErrorTree(stackParser, error[key], key, [exception, ...stack]); |
| 81 | + return event; |
93 | 82 | } |
94 | 83 | } |
0 commit comments