bugsnag-js icon indicating copy to clipboard operation
bugsnag-js copied to clipboard

React Native - Possible Unhandled Promise Rejections

Open ians-shipt opened this issue 3 years ago • 3 comments

Similar issue as in https://github.com/bugsnag/bugsnag-js/issues/1519, but I can't even get it working in a brand new create react app. Posted a comment on that issue. Creating this issue for more visibility.

Describe the bug

When Errors (such as TypeError) happen within an Async function that's not wrapped in a try/catch (such as a function used for the onPress prop), they are not reported to BugSnag.

Steps to reproduce

  1. Create a new React Native project using npx react-native init BugSnagUnhandledRejections --version 0.65.2
  2. Install BugSnag using npx @bugsnag/react-native-cli init, and choose latest (7.17.3)
    • Add appropriate API_KEY when prompted
  3. Add Bugsnag.start() to App component.
  4. Add a button which calls an async function when pressed
  5. See warning log in bundler console, but nothing in Bugsnag
  6. For more robust testing, have a non-async function be called for onPress and don't await the async function when calling (or wrap in a try/catch)

Environment

  • Bugsnag version: 7.17.3
  • React-Native: 0.65.2
  • React: 17.0.2
  • Device (e.g. iphonex): iPhone Simulator and OnePlus 6T

Example code snippet

// Step 5
const boom = async () => {
  null.reject();
};

// Step 7
const asyncPress = async () => {
  Bugsnag.notify(new Error('create-react app test'));
  await boom();
};

// Step 7
const press = () => {
  asyncPress();
  null.goBoom();
};
Error messages:
Not Logged Logged
image image

ians-shipt avatar Aug 09 '22 14:08 ians-shipt

Hi @ians-shipt - thanks for raising this, I've been able to reproduce this on v0.65 of React Native as per your steps above, but not on v0.64. We're currently investigating and will keep you updated on this thread 👍

luke-belton avatar Aug 16 '22 14:08 luke-belton

Hi @ians-shipt - please could you confirm whether you are only seeing this for dev builds?

Based on the investigation we have done so far, we have a theory that this only happens in dev mode when React Native lazy loads promise rejection handling after Bugsnag has started, but it would be good to confirm that before we implement a workaround!

luke-belton avatar Sep 06 '22 16:09 luke-belton

Hi @luke-belton , apologies for the delayed response!

It would seem this is reproducible even when the test app is not in dev mode. I ran the app on my OnePlus 6T using npx react-native run-android --variant=release and making sure the Metro bundler was not running.

Below is what I see in BugSnag (same as before, the null.reject doesn't get logged)

image

ians-shipt avatar Sep 12 '22 20:09 ians-shipt

Hey @luke-belton , we've upgraded ReactNative and no longer appear to be seeing this, so I'll close this issue out. Thanks to you and the team for looking into it!

ians-shipt avatar Sep 27 '22 16:09 ians-shipt

@ians-shipt I'm facing a similar issue, to which React Native version did you upgrade to solve this problem?

andrecrimb avatar Nov 22 '22 14:11 andrecrimb

@andrecrimb Sorry for the delayed response! We went from 0.65.2 to 0.68.3

ians-shipt avatar Dec 30 '22 16:12 ians-shipt