From a79c097c7c0cc2d0d96b74b93afd8354de0a885a Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 2 Feb 2022 12:31:36 +0100 Subject: [PATCH] fix(integrations): ensure default depth is used when no options provided Ensure that depth option is by default set to 3. That wouldn't happen if the user provided empty object as options. Fixes #4186 --- packages/integrations/src/extraerrordata.ts | 10 +++++++- .../integrations/test/extraerrordata.test.ts | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/integrations/src/extraerrordata.ts b/packages/integrations/src/extraerrordata.ts index de01df6605c0..ca2f13ca1542 100644 --- a/packages/integrations/src/extraerrordata.ts +++ b/packages/integrations/src/extraerrordata.ts @@ -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 diff --git a/packages/integrations/test/extraerrordata.test.ts b/packages/integrations/test/extraerrordata.test.ts index e872b7d99ecc..ed76a2dc75ca 100644 --- a/packages/integrations/test/extraerrordata.test.ts +++ b/packages/integrations/test/extraerrordata.test.ts @@ -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