@@ -4,8 +4,17 @@ import { applyAggregateErrorsToEvent, createStackParser } from '../src/index';
4
4
5
5
const stackParser = createStackParser ( [ 0 , line => ( { filename : line } ) ] ) ;
6
6
const exceptionFromError = ( _stackParser : StackParser , ex : Error ) : Exception => {
7
- return { value : ex . message , mechanism : { type : 'instrument' , handled : true } } ;
7
+ return { value : ex . message , type : ex . name , mechanism : { type : 'instrument' , handled : true } } ;
8
8
} ;
9
+ class FakeAggregateError extends Error {
10
+ public errors : Error [ ] ;
11
+
12
+ constructor ( errors : Error [ ] , message : string ) {
13
+ super ( message ) ;
14
+ this . errors = errors ;
15
+ this . name = 'AggregateError' ;
16
+ }
17
+ }
9
18
10
19
describe ( 'applyAggregateErrorsToEvent()' , ( ) => {
11
20
test ( 'should not do anything if event does not contain an exception' , ( ) => {
@@ -57,6 +66,7 @@ describe('applyAggregateErrorsToEvent()', () => {
57
66
exception : {
58
67
values : [
59
68
{
69
+ type : 'Error' ,
60
70
value : 'Nested Error 2' ,
61
71
mechanism : {
62
72
exception_id : 2 ,
@@ -67,22 +77,22 @@ describe('applyAggregateErrorsToEvent()', () => {
67
77
} ,
68
78
} ,
69
79
{
80
+ type : 'Error' ,
70
81
value : 'Nested Error 1' ,
71
82
mechanism : {
72
83
exception_id : 1 ,
73
84
handled : true ,
74
85
parent_id : 0 ,
75
- is_exception_group : true ,
76
86
source : 'cause' ,
77
87
type : 'chained' ,
78
88
} ,
79
89
} ,
80
90
{
91
+ type : 'Error' ,
81
92
value : 'Root Error' ,
82
93
mechanism : {
83
94
exception_id : 0 ,
84
95
handled : true ,
85
- is_exception_group : true ,
86
96
type : 'instrument' ,
87
97
} ,
88
98
} ,
@@ -123,19 +133,21 @@ describe('applyAggregateErrorsToEvent()', () => {
123
133
124
134
// Last exception in list should be the root exception
125
135
expect ( event . exception ?. values ?. [ event . exception ?. values . length - 1 ] ) . toStrictEqual ( {
136
+ type : 'Error' ,
126
137
value : 'Root Error' ,
127
138
mechanism : {
128
139
exception_id : 0 ,
129
140
handled : true ,
130
- is_exception_group : true ,
131
141
type : 'instrument' ,
132
142
} ,
133
143
} ) ;
134
144
} ) ;
135
145
136
146
test ( 'should keep the original mechanism type for the root exception' , ( ) => {
137
- const fakeAggregateError : ExtendedError = new Error ( 'Root Error' ) ;
138
- fakeAggregateError . errors = [ new Error ( 'Nested Error 1' ) , new Error ( 'Nested Error 2' ) ] ;
147
+ const fakeAggregateError = new FakeAggregateError (
148
+ [ new Error ( 'Nested Error 1' ) , new Error ( 'Nested Error 2' ) ] ,
149
+ 'Root Error' ,
150
+ ) ;
139
151
140
152
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , fakeAggregateError ) ] } } ;
141
153
const eventHint : EventHint = { originalException : fakeAggregateError } ;
@@ -147,10 +159,12 @@ describe('applyAggregateErrorsToEvent()', () => {
147
159
test ( 'should recursively walk mixed errors (Aggregate errors and based on `key`)' , ( ) => {
148
160
const chainedError : ExtendedError = new Error ( 'Nested Error 3' ) ;
149
161
chainedError . cause = new Error ( 'Nested Error 4' ) ;
150
- const fakeAggregateError2 : ExtendedError = new Error ( 'AggregateError2' ) ;
151
- fakeAggregateError2 . errors = [ new Error ( 'Nested Error 2' ) , chainedError ] ;
152
- const fakeAggregateError1 : ExtendedError = new Error ( 'AggregateError1' ) ;
153
- fakeAggregateError1 . errors = [ new Error ( 'Nested Error 1' ) , fakeAggregateError2 ] ;
162
+
163
+ const fakeAggregateError2 = new FakeAggregateError ( [ new Error ( 'Nested Error 2' ) , chainedError ] , 'AggregateError2' ) ;
164
+ const fakeAggregateError1 = new FakeAggregateError (
165
+ [ new Error ( 'Nested Error 1' ) , fakeAggregateError2 ] ,
166
+ 'AggregateError1' ,
167
+ ) ;
154
168
155
169
const event : Event = { exception : { values : [ exceptionFromError ( stackParser , fakeAggregateError1 ) ] } } ;
156
170
const eventHint : EventHint = { originalException : fakeAggregateError1 } ;
@@ -167,17 +181,18 @@ describe('applyAggregateErrorsToEvent()', () => {
167
181
source : 'cause' ,
168
182
type : 'chained' ,
169
183
} ,
184
+ type : 'Error' ,
170
185
value : 'Nested Error 4' ,
171
186
} ,
172
187
{
173
188
mechanism : {
174
189
exception_id : 4 ,
175
190
handled : true ,
176
- is_exception_group : true ,
177
191
parent_id : 2 ,
178
192
source : 'errors[1]' ,
179
193
type : 'chained' ,
180
194
} ,
195
+ type : 'Error' ,
181
196
value : 'Nested Error 3' ,
182
197
} ,
183
198
{
@@ -188,6 +203,7 @@ describe('applyAggregateErrorsToEvent()', () => {
188
203
source : 'errors[0]' ,
189
204
type : 'chained' ,
190
205
} ,
206
+ type : 'Error' ,
191
207
value : 'Nested Error 2' ,
192
208
} ,
193
209
{
@@ -199,6 +215,7 @@ describe('applyAggregateErrorsToEvent()', () => {
199
215
source : 'errors[1]' ,
200
216
type : 'chained' ,
201
217
} ,
218
+ type : 'AggregateError' ,
202
219
value : 'AggregateError2' ,
203
220
} ,
204
221
{
@@ -209,6 +226,7 @@ describe('applyAggregateErrorsToEvent()', () => {
209
226
source : 'errors[0]' ,
210
227
type : 'chained' ,
211
228
} ,
229
+ type : 'Error' ,
212
230
value : 'Nested Error 1' ,
213
231
} ,
214
232
{
@@ -218,6 +236,7 @@ describe('applyAggregateErrorsToEvent()', () => {
218
236
is_exception_group : true ,
219
237
type : 'instrument' ,
220
238
} ,
239
+ type : 'AggregateError' ,
221
240
value : 'AggregateError1' ,
222
241
} ,
223
242
] ,
@@ -239,6 +258,7 @@ describe('applyAggregateErrorsToEvent()', () => {
239
258
exception : {
240
259
values : [
241
260
{
261
+ type : 'Error' ,
242
262
value : 'Nested Error 2' ,
243
263
mechanism : {
244
264
exception_id : 2 ,
@@ -249,22 +269,22 @@ describe('applyAggregateErrorsToEvent()', () => {
249
269
} ,
250
270
} ,
251
271
{
272
+ type : 'Error' ,
252
273
value : 'Nested Error 1' ,
253
274
mechanism : {
254
275
exception_id : 1 ,
255
276
handled : true ,
256
277
parent_id : 0 ,
257
- is_exception_group : true ,
258
278
source : 'cause' ,
259
279
type : 'chained' ,
260
280
} ,
261
281
} ,
262
282
{
283
+ type : 'Error' ,
263
284
value : 'Root Error' ,
264
285
mechanism : {
265
286
exception_id : 0 ,
266
287
handled : true ,
267
- is_exception_group : true ,
268
288
type : 'instrument' ,
269
289
} ,
270
290
} ,
@@ -287,6 +307,7 @@ describe('applyAggregateErrorsToEvent()', () => {
287
307
exception : {
288
308
values : [
289
309
{
310
+ type : 'Error' ,
290
311
value : 'Nested Error 2 ...' ,
291
312
mechanism : {
292
313
exception_id : 2 ,
@@ -297,22 +318,22 @@ describe('applyAggregateErrorsToEvent()', () => {
297
318
} ,
298
319
} ,
299
320
{
321
+ type : 'Error' ,
300
322
value : 'Nested Error 1 ...' ,
301
323
mechanism : {
302
324
exception_id : 1 ,
303
325
handled : true ,
304
326
parent_id : 0 ,
305
- is_exception_group : true ,
306
327
source : 'cause' ,
307
328
type : 'chained' ,
308
329
} ,
309
330
} ,
310
331
{
332
+ type : 'Error' ,
311
333
value : 'Root Error with...' ,
312
334
mechanism : {
313
335
exception_id : 0 ,
314
336
handled : true ,
315
- is_exception_group : true ,
316
337
type : 'instrument' ,
317
338
} ,
318
339
} ,
0 commit comments