Skip to content

Commit 1598a7a

Browse files
author
Luca Forstner
committed
Add it to node
1 parent 5feacb2 commit 1598a7a

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

packages/browser/src/integrations/linkederrors.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
2-
import type { Event, EventHint, ExtendedError, Integration, StackParser } from '@sentry/types';
1+
import type { Event, EventHint, EventProcessor, ExtendedError, Hub, Integration, StackParser } from '@sentry/types';
32
import { aggreagateExceptionsFromError, isInstanceOf } from '@sentry/utils';
43

54
import { exceptionFromError } from '../eventbuilder';
@@ -45,7 +44,7 @@ export class LinkedErrors implements Integration {
4544
/**
4645
* @inheritDoc
4746
*/
48-
public setupOnce(): void {
47+
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
4948
const client = getCurrentHub().getClient();
5049
if (!client) {
5150
return;

packages/node/src/integrations/linkederrors.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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';
43

54
import { exceptionFromError } from '../eventbuilder';
65
import { ContextLines } from './contextlines';
@@ -41,7 +40,7 @@ export class LinkedErrors implements Integration {
4140
/**
4241
* @inheritDoc
4342
*/
44-
public setupOnce(): void {
43+
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
4544
addGlobalEventProcessor(async (event: Event, hint: EventHint) => {
4645
const hub = getCurrentHub();
4746
const self = hub.getIntegration(LinkedErrors);
@@ -69,26 +68,16 @@ export class LinkedErrors implements Integration {
6968
return event;
7069
}
7170

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+
);
8978

90-
const exception = exceptionFromError(stackParser, error[key]);
79+
event.exception.values = [...linkedErrors, ...event.exception.values];
9180

92-
return this._walkErrorTree(stackParser, error[key], key, [exception, ...stack]);
81+
return event;
9382
}
9483
}

0 commit comments

Comments
 (0)