From 7259f12cc4a0f2f4195ae39f6d4e2599840bc78a Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 11 Oct 2024 14:22:27 +0300 Subject: [PATCH] fix: Handles error with string cause (#4163) --- CHANGELOG.md | 1 + src/js/integrations/nativelinkederrors.ts | 8 +++-- test/integrations/nativelinkederrors.test.ts | 37 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50643db308..88edc6e3ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Handles error with string cause ([#4163](https://github.com/getsentry/sentry-react-native/pull/4163)) - Use `appLaunchedInForeground` to determine invalid app start data on Android ([#4146](https://github.com/getsentry/sentry-react-native/pull/4146)) - Upload source maps for all release variants on Android (not only the last found) ([#4125](https://github.com/getsentry/sentry-react-native/pull/4125)) diff --git a/src/js/integrations/nativelinkederrors.ts b/src/js/integrations/nativelinkederrors.ts index f35d339f63..af1a525c71 100644 --- a/src/js/integrations/nativelinkederrors.ts +++ b/src/js/integrations/nativelinkederrors.ts @@ -13,7 +13,7 @@ import type { StackFrame, StackParser, } from '@sentry/types'; -import { isInstanceOf, isPlainObject } from '@sentry/utils'; +import { isInstanceOf, isPlainObject, isString } from '@sentry/utils'; import type { NativeStackFrames } from '../NativeRNSentry'; import { NATIVE } from '../wrapper'; @@ -103,7 +103,11 @@ function walkErrorTree( let exception: Exception; let exceptionDebugImages: DebugImage[] | undefined; - if ('stackElements' in linkedError) { + if (isString(linkedError)) { + exception = { + value: linkedError, + }; + } else if ('stackElements' in linkedError) { // isJavaException exception = exceptionFromJavaStackElements(linkedError); } else if ('stackReturnAddresses' in linkedError) { diff --git a/test/integrations/nativelinkederrors.test.ts b/test/integrations/nativelinkederrors.test.ts index 3f1781fd40..6dbc73fe5b 100644 --- a/test/integrations/nativelinkederrors.test.ts +++ b/test/integrations/nativelinkederrors.test.ts @@ -337,6 +337,43 @@ describe('NativeLinkedErrors', () => { }), ); }); + + it('handles events with a string cause', async () => { + const actualEvent = await executeIntegrationFor( + { + exception: { + values: [ + { + type: 'Error', + value: 'Captured exception', + }, + ], + }, + }, + { + originalException: createNewError({ + message: 'Error with string cause', + cause: 'string cause', + }), + }, + ); + + expect(actualEvent).toEqual( + expect.objectContaining(>{ + exception: { + values: [ + { + type: 'Error', + value: 'Captured exception', + }, + { + value: 'string cause', + }, + ], + }, + }), + ); + }); }); function executeIntegrationFor(mockedEvent: Event, mockedHint: EventHint): Event | null {