diff --git a/packages/core/src/integrations/extraerrordata.ts b/packages/core/src/integrations/extraerrordata.ts index ae65739aed5f..59bac56908c3 100644 --- a/packages/core/src/integrations/extraerrordata.ts +++ b/packages/core/src/integrations/extraerrordata.ts @@ -34,7 +34,7 @@ const _extraErrorDataIntegration = ((options: Partial = { return { name: INTEGRATION_NAME, processEvent(event, hint, client) { - const { maxValueLength = 250 } = client.getOptions(); + const { maxValueLength } = client.getOptions(); return _enhanceEventWithErrorData(event, hint, depth, captureErrorCause, maxValueLength); }, }; @@ -47,7 +47,7 @@ function _enhanceEventWithErrorData( hint: EventHint = {}, depth: number, captureErrorCause: boolean, - maxValueLength: number, + maxValueLength: number | undefined, ): Event { if (!hint.originalException || !isError(hint.originalException)) { return event; @@ -85,7 +85,7 @@ function _enhanceEventWithErrorData( function _extractErrorData( error: ExtendedError, captureErrorCause: boolean, - maxValueLength: number, + maxValueLength: number | undefined, ): Record | null { // We are trying to enhance already existing event, so no harm done if it won't succeed try { @@ -109,7 +109,12 @@ function _extractErrorData( continue; } const value = error[key]; - extraErrorInfo[key] = isError(value) || typeof value === 'string' ? truncate(`${value}`, maxValueLength) : value; + extraErrorInfo[key] = + isError(value) || typeof value === 'string' + ? maxValueLength + ? truncate(`${value}`, maxValueLength) + : `${value}` + : value; } // Error.cause is a standard property that is non enumerable, we therefore need to access it separately. diff --git a/packages/core/src/types-hoist/options.ts b/packages/core/src/types-hoist/options.ts index 1f172aaa1f4a..2d4c0e6b43a4 100644 --- a/packages/core/src/types-hoist/options.ts +++ b/packages/core/src/types-hoist/options.ts @@ -184,8 +184,6 @@ export interface ClientOptions { }); }); + it('should not truncate extra data without maxValueLength', () => { + const error = new TypeError('foo') as ExtendedError; + error.baz = 42; + error.foo = 'a'.repeat(300); + + const enhancedEvent = extraErrorData.processEvent?.( + event, + { + originalException: error, + }, + new TestClient(getDefaultTestClientOptions()), + ) as Event; + + expect(enhancedEvent.contexts).toEqual({ + TypeError: { + baz: 42, + foo: `${'a'.repeat(300)}`, + }, + }); + }); + 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') as ExtendedError;