From ead23093ebef2564d24290af70c28a900607aae0 Mon Sep 17 00:00:00 2001 From: ha1fstack <61955474+ha1fstack@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:24:05 +0900 Subject: [PATCH 1/2] feat --- packages/core/src/integrations/extraerrordata.ts | 7 ++++++- .../test/lib/integrations/extraerrordata.test.ts | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/core/src/integrations/extraerrordata.ts b/packages/core/src/integrations/extraerrordata.ts index 291648244f6c..64acd10e113f 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 causeName = error.cause.name || error.cause.constructor.name; + extraErrorInfo.cause = { [causeName]: _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)}...`, + }, + }, }, }); }); From e3b12e7ee23dc151ae9de250800d57b957a5adc8 Mon Sep 17 00:00:00 2001 From: ha1fstack <61955474+ha1fstack@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:24:30 +0900 Subject: [PATCH 2/2] chore: rename variable --- packages/core/src/integrations/extraerrordata.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/integrations/extraerrordata.ts b/packages/core/src/integrations/extraerrordata.ts index 64acd10e113f..ae65739aed5f 100644 --- a/packages/core/src/integrations/extraerrordata.ts +++ b/packages/core/src/integrations/extraerrordata.ts @@ -116,8 +116,8 @@ function _extractErrorData( // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause if (captureErrorCause && error.cause !== undefined) { if (isError(error.cause)) { - const causeName = error.cause.name || error.cause.constructor.name; - extraErrorInfo.cause = { [causeName]: _extractErrorData(error.cause as ExtendedError, false, maxValueLength) }; + const errorName = error.cause.name || error.cause.constructor.name; + extraErrorInfo.cause = { [errorName]: _extractErrorData(error.cause as ExtendedError, false, maxValueLength) }; } else { extraErrorInfo.cause = error.cause; }