Skip to content

Commit e714217

Browse files
authored
fix(integrations): Add default for ExtraErrorData's depth option (#4487)
Ensure that `ExtraErrorData`'s `depth` option is by default set to 3. Currently, if the user provides an empty options object, `depth` gets set to `undefined`. Fixes #4186
1 parent f89a842 commit e714217

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/integrations/src/extraerrordata.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ export class ExtraErrorData implements Integration {
1818
*/
1919
public name: string = ExtraErrorData.id;
2020

21+
/** JSDoc */
22+
private readonly _options: ExtraErrorDataOptions;
23+
2124
/**
2225
* @inheritDoc
2326
*/
24-
public constructor(private readonly _options: ExtraErrorDataOptions = { depth: 3 }) {}
27+
public constructor(options?: ExtraErrorDataOptions) {
28+
this._options = {
29+
depth: 3,
30+
...options,
31+
};
32+
}
2533

2634
/**
2735
* @inheritDoc

packages/integrations/test/extraerrordata.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ describe('ExtraErrorData()', () => {
4242
});
4343
});
4444

45+
it('should stringify up to 3 nested levels by default', () => {
46+
const error = new TypeError('foo') as ExtendedError;
47+
error['1'] = {
48+
2: {
49+
3: {
50+
4: 'foo',
51+
},
52+
},
53+
};
54+
55+
const enhancedEvent = extraErrorData.enhanceEventWithErrorData(event, {
56+
originalException: error,
57+
});
58+
59+
expect(enhancedEvent.contexts).toEqual({
60+
TypeError: {
61+
1: {
62+
2: {
63+
3: '[Object]',
64+
},
65+
},
66+
},
67+
});
68+
});
69+
4570
it('should not remove previous data existing in extra field', () => {
4671
event = {
4772
// @ts-ignore Allow contexts on event

0 commit comments

Comments
 (0)