Skip to content

Commit

Permalink
fix: Handles error with string cause (#4163)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis authored Oct 11, 2024
1 parent c773341 commit 7259f12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
8 changes: 6 additions & 2 deletions src/js/integrations/nativelinkederrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
37 changes: 37 additions & 0 deletions test/integrations/nativelinkederrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Partial<Event>>{
exception: {
values: [
{
type: 'Error',
value: 'Captured exception',
},
{
value: 'string cause',
},
],
},
}),
);
});
});

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

0 comments on commit 7259f12

Please sign in to comment.