Skip to content

Commit d195211

Browse files
authored
Merge branch 'develop' into abhi-twp-node-http
2 parents f9c8d0e + 1d8c81f commit d195211

File tree

7 files changed

+185
-356
lines changed

7 files changed

+185
-356
lines changed
Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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, Hub, Integration } from '@sentry/types';
2+
import { applyAggregateErrorsToEvent } from '@sentry/utils';
43

5-
import type { BrowserClient } from '../client';
64
import { exceptionFromError } from '../eventbuilder';
75

86
const DEFAULT_KEY = 'cause';
@@ -46,49 +44,26 @@ export class LinkedErrors implements Integration {
4644
/**
4745
* @inheritDoc
4846
*/
49-
public setupOnce(): void {
50-
const client = getCurrentHub().getClient<BrowserClient>();
51-
if (!client) {
52-
return;
53-
}
47+
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
5448
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
55-
const self = getCurrentHub().getIntegration(LinkedErrors);
56-
return self ? _handler(client.getOptions().stackParser, self._key, self._limit, event, hint) : event;
57-
});
58-
}
59-
}
49+
const hub = getCurrentHub();
50+
const client = hub.getClient();
51+
const self = hub.getIntegration(LinkedErrors);
6052

61-
/**
62-
* @inheritDoc
63-
*/
64-
export function _handler(
65-
parser: StackParser,
66-
key: string,
67-
limit: number,
68-
event: Event,
69-
hint?: EventHint,
70-
): Event | null {
71-
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
72-
return event;
73-
}
74-
const linkedErrors = _walkErrorTree(parser, limit, hint.originalException as ExtendedError, key);
75-
event.exception.values = [...linkedErrors, ...event.exception.values];
76-
return event;
77-
}
53+
if (!client || !self) {
54+
return event;
55+
}
56+
57+
applyAggregateErrorsToEvent(
58+
exceptionFromError,
59+
client.getOptions().stackParser,
60+
self._key,
61+
self._limit,
62+
event,
63+
hint,
64+
);
7865

79-
/**
80-
* JSDOC
81-
*/
82-
export function _walkErrorTree(
83-
parser: StackParser,
84-
limit: number,
85-
error: ExtendedError,
86-
key: string,
87-
stack: Exception[] = [],
88-
): Exception[] {
89-
if (!isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {
90-
return stack;
66+
return event;
67+
});
9168
}
92-
const exception = exceptionFromError(parser, error[key]);
93-
return _walkErrorTree(parser, limit, error[key], key, [exception, ...stack]);
9469
}

packages/browser/test/unit/integrations/linkederrors.test.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.
Lines changed: 17 additions & 39 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, Hub, Integration } from '@sentry/types';
2+
import { applyAggregateErrorsToEvent } from '@sentry/utils';
43

54
import { exceptionFromError } from '../eventbuilder';
65
import { ContextLines } from './contextlines';
@@ -41,15 +40,25 @@ export class LinkedErrors implements Integration {
4140
/**
4241
* @inheritDoc
4342
*/
44-
public setupOnce(): void {
45-
addGlobalEventProcessor(async (event: Event, hint: EventHint) => {
43+
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
44+
addGlobalEventProcessor(async (event: Event, hint?: EventHint) => {
4645
const hub = getCurrentHub();
47-
const self = hub.getIntegration(LinkedErrors);
4846
const client = hub.getClient();
49-
if (client && self && self._handler && typeof self._handler === 'function') {
50-
self._handler(client.getOptions().stackParser, event, hint);
47+
const self = hub.getIntegration(LinkedErrors);
48+
49+
if (!client || !self) {
50+
return event;
5151
}
5252

53+
applyAggregateErrorsToEvent(
54+
exceptionFromError,
55+
client.getOptions().stackParser,
56+
self._key,
57+
self._limit,
58+
event,
59+
hint,
60+
);
61+
5362
// If the ContextLines integration is enabled, we add source code context to linked errors
5463
// because we can't guarantee the order that integrations are run.
5564
const contextLines = getCurrentHub().getIntegration(ContextLines);
@@ -60,35 +69,4 @@ export class LinkedErrors implements Integration {
6069
return event;
6170
});
6271
}
63-
64-
/**
65-
* @inheritDoc
66-
*/
67-
private _handler(stackParser: StackParser, event: Event, hint: EventHint): Event {
68-
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
69-
return event;
70-
}
71-
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-
}
89-
90-
const exception = exceptionFromError(stackParser, error[key]);
91-
92-
return this._walkErrorTree(stackParser, error[key], key, [exception, ...stack]);
93-
}
9472
}

0 commit comments

Comments
 (0)