Unhandled promise rejections are not logged to sentry
My feature request is connected to the bug https://github.com/getsentry/sentry-react-native/issues/1077.
I've tried the solution from docs, but it didn't work out for me. So I found another solution with polyfilling existing Promise in React Native.
I've used this package
import { setUnhandledPromiseRejectionTracker } from 'react-native-promise-rejection-utils';
import { getCurrentHub } from '@sentry/core';
setUnhandledPromiseRejectionTracker((id, error) => {
getCurrentHub().captureException(error, {
data: { id },
originalException: error,
});
});
Inside the react-native-promise-rejection-utils package polyfills the existing promise. You can check it out here
So I propose changing the method, removing the check for the promise version and using the package react-native-promise-rejection-utils or polyfill directly without relaying on this package.
I think this solution is better in many ways:
- It doesn't require user to do or check anything. It just works
_checkPromiseVersioncan be removed
@jennmueng can you have a look at it?
@Arhane thanks for the report.
I've tried the solution from docs, but it didn't work out for me
can you provide a minimal reproducible example? it worked on our end.
@marandaneto @Arhane We wanted to avoid polyfilling the global promise instance inside the SDK in fear of compatibility issues with older versions of React Native...but now that I've given it some more thought it might be a good solution out as RN hasn't really changed anything regarding Promises for a while although maybe a third party SDK shouldn't have the behavior of polyfilling commonly used global feature. Will need to think this one through.
@marandaneto I will try to make a demo.
@jennmueng I know, this isn't the best solution, but it seems more user-friendly, than version-matching. I agree, that third party SDK shouldn't polyfill the promise. I guess, we can hide it behind some flag? Like polyfillPromise or something more eloquent
I have the same issue. I did match the versions, but that doesn't help.
grep "promise" node_modules/react-native/package.json
"promise": "^8.0.3",
grep "promise" ./package.json
"promise": "^8.0.3"
Possible Unhandled Promise Rejection (id: 0):
TypeError: Attempted to assign to readonly property.
Also, setting debug: true doesn't show me the [Sentry] Unhandled promise rejections will be caught by Sentry. message.
@pors What version of the SDK are you running, which version RN, is this on iOS/Android/Both, and are you running Hermes?
@jennmueng:
- SDK 44
- RN 0.64.3
- Only tested on iOS
- Hermes: yes
I have the same issue with:
- RN 0.66.4
- Android
- iOS
- Hermes: yes
- "@sentry/react-native": "^3.2.10",
Please issue an urgent fix. Thanks!
hey, mind testing out the latest release that includes this fix? https://github.com/getsentry/sentry-react-native/releases/tag/3.2.11 Feedback welcomed, thanks.
Just tested the latest version (3.2.11) and it works.
But it works without patchGlobalPromise too, which is strange.
Tested with this code
Promise.reject('Test the new version of sentry');
and Sentry.init
Sentry.init({
dsn: SENTRY_DSN,
});
thanks, the reason is probably described here @Arhane https://docs.sentry.io/platforms/react-native/troubleshooting/#unhandled-promise-rejections