Skip to content

Commit 7259f12

Browse files
authored
fix: Handles error with string cause (#4163)
1 parent c773341 commit 7259f12

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- Handles error with string cause ([#4163](https://github.com/getsentry/sentry-react-native/pull/4163))
78
- Use `appLaunchedInForeground` to determine invalid app start data on Android ([#4146](https://github.com/getsentry/sentry-react-native/pull/4146))
89
- Upload source maps for all release variants on Android (not only the last found) ([#4125](https://github.com/getsentry/sentry-react-native/pull/4125))
910

src/js/integrations/nativelinkederrors.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
StackFrame,
1414
StackParser,
1515
} from '@sentry/types';
16-
import { isInstanceOf, isPlainObject } from '@sentry/utils';
16+
import { isInstanceOf, isPlainObject, isString } from '@sentry/utils';
1717

1818
import type { NativeStackFrames } from '../NativeRNSentry';
1919
import { NATIVE } from '../wrapper';
@@ -103,7 +103,11 @@ function walkErrorTree(
103103

104104
let exception: Exception;
105105
let exceptionDebugImages: DebugImage[] | undefined;
106-
if ('stackElements' in linkedError) {
106+
if (isString(linkedError)) {
107+
exception = {
108+
value: linkedError,
109+
};
110+
} else if ('stackElements' in linkedError) {
107111
// isJavaException
108112
exception = exceptionFromJavaStackElements(linkedError);
109113
} else if ('stackReturnAddresses' in linkedError) {

test/integrations/nativelinkederrors.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,43 @@ describe('NativeLinkedErrors', () => {
337337
}),
338338
);
339339
});
340+
341+
it('handles events with a string cause', async () => {
342+
const actualEvent = await executeIntegrationFor(
343+
{
344+
exception: {
345+
values: [
346+
{
347+
type: 'Error',
348+
value: 'Captured exception',
349+
},
350+
],
351+
},
352+
},
353+
{
354+
originalException: createNewError({
355+
message: 'Error with string cause',
356+
cause: 'string cause',
357+
}),
358+
},
359+
);
360+
361+
expect(actualEvent).toEqual(
362+
expect.objectContaining(<Partial<Event>>{
363+
exception: {
364+
values: [
365+
{
366+
type: 'Error',
367+
value: 'Captured exception',
368+
},
369+
{
370+
value: 'string cause',
371+
},
372+
],
373+
},
374+
}),
375+
);
376+
});
340377
});
341378

342379
function executeIntegrationFor(mockedEvent: Event, mockedHint: EventHint): Event | null {

0 commit comments

Comments
 (0)