-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathlinkederrors.test.ts
110 lines (94 loc) · 4.38 KB
/
linkederrors.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { ExtendedError } from '@sentry/types';
import { BrowserClient } from '../../../src/client';
import * as LinkedErrorsModule from '../../../src/integrations/linkederrors';
describe('LinkedErrors', () => {
describe('handler', () => {
it('should bail out if event does not contain exception', () => {
const event = {
message: 'foo',
};
const result = LinkedErrorsModule._handler('cause', 5, event);
expect(result).toEqual(event);
});
it('should bail out if event contains exception, but no hint', () => {
const event = {
exception: {
values: [],
},
message: 'foo',
};
const result = LinkedErrorsModule._handler('cause', 5, event);
expect(result).toEqual(event);
});
it('should recursively walk error to find linked exceptions and assign them to the event', async () => {
const three: ExtendedError = new SyntaxError('three');
const two: ExtendedError = new TypeError('two');
two.cause = three;
const one: ExtendedError = new Error('one');
one.cause = two;
const originalException = one;
const client = new BrowserClient({});
return client.eventFromException(originalException).then(event => {
const result = LinkedErrorsModule._handler('cause', 5, event, {
originalException,
});
// It shouldn't include root exception, as it's already processed in the event by the main error handler
expect(result.exception.values.length).toBe(3);
expect(result.exception.values[0].type).toBe('SyntaxError');
expect(result.exception.values[0].value).toBe('three');
expect(result.exception.values[0].stacktrace).toHaveProperty('frames');
expect(result.exception.values[1].type).toBe('TypeError');
expect(result.exception.values[1].value).toBe('two');
expect(result.exception.values[1].stacktrace).toHaveProperty('frames');
expect(result.exception.values[2].type).toBe('Error');
expect(result.exception.values[2].value).toBe('one');
expect(result.exception.values[2].stacktrace).toHaveProperty('frames');
});
});
it('should allow to change walk key', async () => {
const three: ExtendedError = new SyntaxError('three');
const two: ExtendedError = new TypeError('two');
two.reason = three;
const one: ExtendedError = new Error('one');
one.reason = two;
const originalException = one;
const client = new BrowserClient({});
return client.eventFromException(originalException).then(event => {
const result = LinkedErrorsModule._handler('reason', 5, event, {
originalException,
});
expect(result.exception.values.length).toBe(3);
expect(result.exception.values[0].type).toBe('SyntaxError');
expect(result.exception.values[0].value).toBe('three');
expect(result.exception.values[0].stacktrace).toHaveProperty('frames');
expect(result.exception.values[1].type).toBe('TypeError');
expect(result.exception.values[1].value).toBe('two');
expect(result.exception.values[1].stacktrace).toHaveProperty('frames');
expect(result.exception.values[2].type).toBe('Error');
expect(result.exception.values[2].value).toBe('one');
expect(result.exception.values[2].stacktrace).toHaveProperty('frames');
});
});
it('should allow to change stack size limit', async () => {
const one: ExtendedError = new Error('one');
const two: ExtendedError = new TypeError('two');
const three: ExtendedError = new SyntaxError('three');
one.cause = two;
two.cause = three;
const client = new BrowserClient({});
const originalException = one;
return client.eventFromException(originalException).then(event => {
const result = LinkedErrorsModule._handler('cause', 2, event, {
originalException,
});
expect(result.exception.values.length).toBe(2);
expect(result.exception.values[0].type).toBe('TypeError');
expect(result.exception.values[0].value).toBe('two');
expect(result.exception.values[0].stacktrace).toHaveProperty('frames');
expect(result.exception.values[1].type).toBe('Error');
expect(result.exception.values[1].value).toBe('one');
expect(result.exception.values[1].stacktrace).toHaveProperty('frames');
});
});
});
});