sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Exceptions get swallowed on Android

Open christophermark opened this issue 7 years ago • 3 comments

OS:

  • [ ] Windows
  • [X] MacOS
  • [ ] Linux

Platform:

  • [ ] iOS
  • [X] Android

Output of node -v && npm -v && npm ls --prod --depth=0

v8.12.0
5.2.0

[email protected]

I have following issue:

A crash on Android is getting swallowed by Sentry. Seems to be a behavior change between react-native-sentry 0.38.3 --> 0.40.2 (latest). Earlier version 38 throws and reports the error as expected, whereas the latest version swallows it.

Steps to reproduce

I had a line of code which causes a crash on Android:

var foo = 10;
var bar = {...foo};

Upgrading react-native-sentry from 0.38.3 to the latest 0.40.2 changed the behavior where the app doesn't crash and the error is not reported to Sentry. So to reproduce:

  • Upgrade to 0.40.2
  • Manually log a separate event to Sentry
    • The caught exception is shown in the breadcrumbs

Actual result

  • The exception gets caught by Sentry and the app doesn't crash as it's supposed to
  • The exception doesn't get reported to Sentry
    • Instead it's included in the breadcrumbs
Screenshot of the error within the breadcrumbs of another event

image


Important detail here is that I had to manually push an event to Sentry to discover that there was a crash happening in the background. Is Sentry wrapping all errors in a try-catch and not re-throwing said errors?

Expected result

  • Downgrade to 0.38.3 to reproduce expected result
  • The app should crash
  • Sentry should report this crash/exception
Screenshot of the error within the breadcrumbs of another event

image

christophermark avatar Dec 20 '18 18:12 christophermark

Hey @christophermark, did you find a solution or did u just downgrade back to 0.38.3? We are having the same problem (#470)

derN3rd avatar Dec 30 '18 23:12 derN3rd

@derN3rd yeah, we found out what was happening. This ended up being an issue with promises and unhandled promise rejections.

The short version of the issue is that other libraries (fetch for network requests, for example) can potentially use a different instance of Promise, so the built-in Promise error handling in Sentry may not get triggered.

Fortunately, you can set a global promise library, and the rejection handler for it:

const BluebirdPromise = require('bluebird');
global.Promise = BluebirdPromise;
Promise.onPossiblyUnhandledRejection((e, promise) => {
    throw e;
    // Instead of throwing here, we manually fired off an event to Sentry using the error object
})

christophermark avatar Jan 02 '19 18:01 christophermark

In 1.3.0, this is still happening.

leedan77 avatar Feb 13 '20 02:02 leedan77