Skip to content

Commit

Permalink
Handles error with string cause
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Oct 10, 2024
1 parent c773341 commit 1aeb779
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 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,9 @@ 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 1aeb779

Please sign in to comment.