Fixing uncatchable, crashing, exception on Android #355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: This does not seem to occur on iOS. We believe that it fails silently which is also an error. We have not done extensive testing there.
We found an issue on Android (8.1 was used) where if we used the public DSN URL we would get an exception citing that we were missing the Sentry secret. In react native, this gave us a red box with the error but it crashed our app. We tried to wrap in a try/catch but no luck.
The error was happening asynchronously in the Sentry Java SDK and not being broadcasted over the RN bridge like you would expect (note this line
errorCallback.invoke(e.getMessage());
, whereerrorCallback
is of type Callback from the RN Callback class), causing the error to get lost and our app unable to recover.To fix this we wanted to
await
on the asynchronous operation. So we created a new methodasync customInit()
that returns a Promise that we await on.In that Promise, we resolve/reject based on if the error/success callback is called.
await
ing on theinstall()
method allows us to wrap that call in a try/catch in case something does throw either Native-ly or in JavaScript.This was a very concerning bug to us, that our Error Reporting tool would throw an uncatchable error on initialization.
If your SDK is throwing exceptions upon startup, how will it behave now that this PR fixes the uncaught exception? If we catch this error and then another part of our code tries to capture an exception with sentry what happens? Have you thought about that?
If we had properly set the secret we never would have caught this! And in the future, if we improperly updated the secret or fat fingered the DSN URL then we would have users with essentially bricked apps that would have lost as customers.
While we have forked the repo we would hope that this would be either merged or otherwise patched in the official react-native-sentry repository.