Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Handles error with string cause #4163

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading