Skip to content

Commit 9041c1d

Browse files
authored
fix: Make sure that handler exists for linkederrors integration (#2742)
* fix: Make sure that handler exists for linkederrors integration
1 parent bc52769 commit 9041c1d

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

packages/node/src/integrations/linkederrors.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class LinkedErrors implements Integration {
1313
* @inheritDoc
1414
*/
1515
public readonly name: string = LinkedErrors.id;
16+
1617
/**
1718
* @inheritDoc
1819
*/
@@ -43,7 +44,8 @@ export class LinkedErrors implements Integration {
4344
addGlobalEventProcessor((event: Event, hint?: EventHint) => {
4445
const self = getCurrentHub().getIntegration(LinkedErrors);
4546
if (self) {
46-
return (self.handler(event, hint) as unknown) as PromiseLike<Event>;
47+
const handler = self._handler && self._handler.bind(self);
48+
return typeof handler === 'function' ? handler(event, hint) : event;
4749
}
4850
return event;
4951
});
@@ -52,13 +54,13 @@ export class LinkedErrors implements Integration {
5254
/**
5355
* @inheritDoc
5456
*/
55-
public handler(event: Event, hint?: EventHint): PromiseLike<Event> {
57+
private _handler(event: Event, hint?: EventHint): PromiseLike<Event> {
5658
if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {
5759
return SyncPromise.resolve(event);
5860
}
5961

6062
return new SyncPromise<Event>(resolve => {
61-
this.walkErrorTree(hint.originalException as Error, this._key)
63+
this._walkErrorTree(hint.originalException as Error, this._key)
6264
.then((linkedErrors: Exception[]) => {
6365
if (event && event.exception && event.exception.values) {
6466
event.exception.values = [...linkedErrors, ...event.exception.values];
@@ -74,14 +76,14 @@ export class LinkedErrors implements Integration {
7476
/**
7577
* @inheritDoc
7678
*/
77-
public walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): PromiseLike<Exception[]> {
79+
private _walkErrorTree(error: ExtendedError, key: string, stack: Exception[] = []): PromiseLike<Exception[]> {
7880
if (!isInstanceOf(error[key], Error) || stack.length + 1 >= this._limit) {
7981
return SyncPromise.resolve(stack);
8082
}
8183
return new SyncPromise<Exception[]>((resolve, reject) => {
8284
getExceptionFromError(error[key])
8385
.then((exception: Exception) => {
84-
this.walkErrorTree(error[key], key, [exception, ...stack])
86+
this._walkErrorTree(error[key], key, [exception, ...stack])
8587
.then(resolve)
8688
.then(null, () => {
8789
reject();

packages/node/test/integrations/linkederrors.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ describe('LinkedErrors', () => {
1414
describe('handler', () => {
1515
it('should bail out if event doesnt contain exception', async () => {
1616
expect.assertions(2);
17-
const spy = jest.spyOn(linkedErrors, 'walkErrorTree');
17+
const spy = jest.spyOn(linkedErrors, '_walkErrorTree');
1818
const event = {
1919
message: 'foo',
2020
};
21-
return linkedErrors.handler(event).then((result: any) => {
21+
return linkedErrors._handler(event).then((result: any) => {
2222
expect(spy.mock.calls.length).toEqual(0);
2323
expect(result).toEqual(event);
2424
});
2525
});
2626

2727
it('should bail out if event contains exception, but no hint', async () => {
2828
expect.assertions(2);
29-
const spy = jest.spyOn(linkedErrors, 'walkErrorTree');
29+
const spy = jest.spyOn(linkedErrors, '_walkErrorTree');
3030
const one = new Error('originalException');
3131
const backend = new NodeBackend({});
3232
let event: Event | undefined;
3333
return backend
3434
.eventFromException(one)
3535
.then(eventFromException => {
3636
event = eventFromException;
37-
return linkedErrors.handler(eventFromException);
37+
return linkedErrors._handler(eventFromException);
3838
})
3939
.then(result => {
4040
expect(spy.mock.calls.length).toEqual(0);
@@ -44,7 +44,7 @@ describe('LinkedErrors', () => {
4444

4545
it('should call walkErrorTree if event contains exception and hint with originalException', async () => {
4646
expect.assertions(1);
47-
const spy = jest.spyOn(linkedErrors, 'walkErrorTree').mockImplementation(
47+
const spy = jest.spyOn(linkedErrors, '_walkErrorTree').mockImplementation(
4848
async () =>
4949
new Promise<[]>(resolve => {
5050
resolve([]);
@@ -54,7 +54,7 @@ describe('LinkedErrors', () => {
5454
const backend = new NodeBackend({});
5555
return backend.eventFromException(one).then(event =>
5656
linkedErrors
57-
.handler(event, {
57+
._handler(event, {
5858
originalException: one,
5959
})
6060
.then(_ => {
@@ -74,7 +74,7 @@ describe('LinkedErrors', () => {
7474
const backend = new NodeBackend({});
7575
return backend.eventFromException(one).then(event =>
7676
linkedErrors
77-
.handler(event, {
77+
._handler(event, {
7878
originalException: one,
7979
})
8080
.then((result: any) => {
@@ -107,7 +107,7 @@ describe('LinkedErrors', () => {
107107
const backend = new NodeBackend({});
108108
return backend.eventFromException(one).then(event =>
109109
linkedErrors
110-
.handler(event, {
110+
._handler(event, {
111111
originalException: one,
112112
})
113113
.then((result: any) => {
@@ -140,7 +140,7 @@ describe('LinkedErrors', () => {
140140
const backend = new NodeBackend({});
141141
return backend.eventFromException(one).then(event =>
142142
linkedErrors
143-
.handler(event, {
143+
._handler(event, {
144144
originalException: one,
145145
})
146146
.then((result: any) => {

0 commit comments

Comments
 (0)