diff --git a/packages/core/src/integrations/extraerrordata.ts b/packages/core/src/integrations/extraerrordata.ts index 291648244f6c..ae65739aed5f 100644 --- a/packages/core/src/integrations/extraerrordata.ts +++ b/packages/core/src/integrations/extraerrordata.ts @@ -115,7 +115,12 @@ function _extractErrorData( // Error.cause is a standard property that is non enumerable, we therefore need to access it separately. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause if (captureErrorCause && error.cause !== undefined) { - extraErrorInfo.cause = isError(error.cause) ? error.cause.toString() : error.cause; + if (isError(error.cause)) { + const errorName = error.cause.name || error.cause.constructor.name; + extraErrorInfo.cause = { [errorName]: _extractErrorData(error.cause as ExtendedError, false, maxValueLength) }; + } else { + extraErrorInfo.cause = error.cause; + } } // Check if someone attached `toJSON` method to grab even more properties (eg. axios is doing that) diff --git a/packages/core/test/lib/integrations/extraerrordata.test.ts b/packages/core/test/lib/integrations/extraerrordata.test.ts index a6470c3f6b2c..f935acc689f9 100644 --- a/packages/core/test/lib/integrations/extraerrordata.test.ts +++ b/packages/core/test/lib/integrations/extraerrordata.test.ts @@ -55,9 +55,11 @@ describe('ExtraErrorData()', () => { }); }); - it('doesnt choke on linked errors and stringify names instead', () => { + it('should extract error data from the error cause with the same policy', () => { const error = new TypeError('foo') as ExtendedError; - error.cause = new SyntaxError('bar'); + error.cause = new SyntaxError('bar') as ExtendedError; + error.cause.baz = 42; + error.cause.foo = 'a'.repeat(300); const enhancedEvent = extraErrorData.processEvent?.( event, @@ -69,7 +71,12 @@ describe('ExtraErrorData()', () => { expect(enhancedEvent.contexts).toEqual({ TypeError: { - cause: 'SyntaxError: bar', + cause: { + SyntaxError: { + baz: 42, + foo: `${'a'.repeat(250)}...`, + }, + }, }, }); });