Skip to content

Commit

Permalink
fix: Native wrapper methods don't throw disabled error after re-initi…
Browse files Browse the repository at this point in the history
…alizing (#3093)

Co-authored-by: Kryštof Woldřich <[email protected]>
  • Loading branch information
mateioprea and krystofwoldrich authored Jun 13, 2023
1 parent d74882f commit 22c9338
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Dynamically resolve `collectModulesScript` path to support monorepos ([#3092])(https://github.com/getsentry/sentry-react-native/pull/3092)
- Native wrapper methods don't throw disabled error after re-initializing [#3093](https://github.com/getsentry/sentry-react-native/pull/3093)

### Dependencies

Expand Down
3 changes: 3 additions & 0 deletions src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ export const NATIVE: SentryNativeWrapper = {
'Note: Native Sentry SDK was not initialized automatically, you will need to initialize it manually. If you wish to disable the native SDK and get rid of this warning, pass enableNative: false',
);
}
this.enableNative = true;
return false;
}

if (!options.dsn) {
logger.warn(
'Warning: No DSN was provided. The Sentry SDK will be disabled. Native SDK will also not be initalized.',
);
this.enableNative = false;
return false;
}

Expand All @@ -201,6 +203,7 @@ export const NATIVE: SentryNativeWrapper = {
const nativeIsReady = await RNSentry.initNativeSdk(filteredOptions);

this.nativeIsReady = nativeIsReady;
this.enableNative = true;

return nativeIsReady;
},
Expand Down
1 change: 1 addition & 0 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ describe('Tests ReactNativeClient', () => {

const client = new ReactNativeClient({
...DEFAULT_OPTIONS,
dsn: EXAMPLE_DSN,
enableNative: true,
transport: () => new NativeTransport(),
});
Expand Down
2 changes: 2 additions & 0 deletions test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ describe('Tests Native Wrapper', () => {
});

test('does not initialize with autoInitializeNativeSdk: false', async () => {
NATIVE.enableNative = false;
logger.warn = jest.fn();

await NATIVE.initNativeSdk({
Expand Down Expand Up @@ -487,6 +488,7 @@ describe('Tests Native Wrapper', () => {
});

describe('closeNativeSdk', () => {
NATIVE.enableNative = true;
test('closeNativeSdk calls native bridge', async () => {
await NATIVE.closeNativeSdk();

Expand Down

0 comments on commit 22c9338

Please sign in to comment.