Skip to content

Commit

Permalink
fix(integrations): ensure default depth is used when no options provided
Browse files Browse the repository at this point in the history
Ensure that depth option is by default set to 3. That wouldn't happen
if the user provided empty object as options.

Fixes #4186
  • Loading branch information
rchl committed Feb 2, 2022
1 parent f89a842 commit a79c097
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/integrations/src/extraerrordata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ export class ExtraErrorData implements Integration {
*/
public name: string = ExtraErrorData.id;

/** JSDoc */
private readonly _options: ExtraErrorDataOptions;

/**
* @inheritDoc
*/
public constructor(private readonly _options: ExtraErrorDataOptions = { depth: 3 }) {}
public constructor(options?: ExtraErrorDataOptions) {
this._options = {
depth: 3,
...options,
};
}

/**
* @inheritDoc
Expand Down
25 changes: 25 additions & 0 deletions packages/integrations/test/extraerrordata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ describe('ExtraErrorData()', () => {
});
});

it('should stringify up to 3 nested levels by default', () => {
const error = new TypeError('foo') as ExtendedError;
error['1'] = {
2: {
3: {
4: 'foo',
},
},
};

const enhancedEvent = extraErrorData.enhanceEventWithErrorData(event, {
originalException: error,
});

expect(enhancedEvent.contexts).toEqual({
TypeError: {
1: {
2: {
3: '[Object]',
},
},
},
});
});

it('should not remove previous data existing in extra field', () => {
event = {
// @ts-ignore Allow contexts on event
Expand Down

0 comments on commit a79c097

Please sign in to comment.