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

Unhandled promise rejections will not be caught by Sentry warning not working (only logging message)

Open jer-sen opened this issue 3 years ago • 6 comments

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? @sentry/[email protected]

Steps to Reproduce

Run the app.

Expected Result

There should be one of these logs from https://github.com/getsentry/sentry-react-native/blob/f916f2b3afbb9884f9037b8486539ca6cc8b327c/src/js/integrations/reactnativeerrorhandlers.ts#L141:

  • Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.
  • Unhandled promise rejections will be caught by Sentry.
  • Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.

Actual Result

No message in logs.

Replacing:

logger.warn("Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.");

by

setTimeout(() => console.warn("Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page."), 0);

solves the issue (setTimeout and console instead of logger are both required). Maybe the logger is not yet ready at this time...

jer-sen avatar Jun 08 '22 10:06 jer-sen

@jer-sen where do you init the Sentry SDK? I can't reproduce that, I always get the logs. Can you provide a minimal reproduction example? thanks.

marandaneto avatar Jun 13 '22 06:06 marandaneto

@marandaneto in a file imported from my index.js. I think it's not a bug of Sentry but when a console.log is called before AppRegistry.registerComponent (or registerRootComponent for Expo) has been executed (e.g. at the top level of a file imported directly or indirectly from index.js), the logs are lost. So, for our warnings about Sentry and promises we have 2 options:

  1. ask people in the doc to initialize Sentry not too early, basically in index.js after registering the component or during the root component first render => but Sentry may miss some early errors
  2. add a setTimeout (registering the component is required synchronously, so we are sure that the console.log will be triggered after registering the component)

jer-sen avatar Jun 21 '22 12:06 jer-sen

@jer-sen so it's not about the unhandled promise not working at all, but rather the logging that tells you if it's working or not, does it make sense?

marandaneto avatar Jun 24 '22 11:06 marandaneto

Yes, exactly.

Le ven. 24 juin 2022 à 13:57, Manoel Aranda Neto @.***> a écrit :

@jer-sen https://github.com/jer-sen so it's not about the unhandled promise not working at all, but rather the logging that tells you if it's working or not, does it make sense?

— Reply to this email directly, view it on GitHub https://github.com/getsentry/sentry-react-native/issues/2268#issuecomment-1165501712, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQFELO46KATQTSC76Q2HXTVQWPBHANCNFSM5YGCGJ6Q . You are receiving this because you were mentioned.Message ID: @.***>

jer-sen avatar Jun 24 '22 19:06 jer-sen

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jul 17 '22 00:07 github-actions[bot]

Still an issue!

jer-sen avatar Jul 17 '22 12:07 jer-sen

In our sample app we also init Sentry before AppRegistry.registerComponent(appName, () => App); but the JS logs are printed out as expected.

Example from a run on iOS, Sentry SDK version 4.7.1.

2022-10-27 15:00:17.510197+0200 sample[18388:6697968] [javascript] 'Sentry Logger [log]:', 'Unhandled promise rejections will be caught by Sentry.'

So is this still an issue @jer-sen ?

krystofwoldrich avatar Oct 27 '22 13:10 krystofwoldrich

I will update and try but not now. Probably in 2 weeks.

jer-sen avatar Oct 28 '22 15:10 jer-sen

any updates here @jer-sen ?

marandaneto avatar Nov 15 '22 09:11 marandaneto

any updates here @jer-sen ?

Not yet, but still in my mind

jer-sen avatar Nov 15 '22 09:11 jer-sen

Hi @jer-sen, any update?

krystofwoldrich avatar Nov 28 '22 11:11 krystofwoldrich

Not yet, and not in the coming days. Maybe you should close the issue and I will update you when I will have time to check.

jer-sen avatar Nov 28 '22 11:11 jer-sen

@krystofwoldrich I have (finally!) updated to @sentry/[email protected] (latest version supported by sentry-expo) and the issue is still here. When I patch (with patch-package) @sentry/react-native like this

diff --git a/node_modules/@sentry/react-native/dist/js/integrations/reactnativeerrorhandlers.js b/node_modules/@sentry/react-native/dist/js/integrations/reactnativeerrorhandlers.js
index ab21a2a..09388e5 100644
--- a/node_modules/@sentry/react-native/dist/js/integrations/reactnativeerrorhandlers.js
+++ b/node_modules/@sentry/react-native/dist/js/integrations/reactnativeerrorhandlers.js
@@ -93,14 +93,20 @@ export class ReactNativeErrorHandlers {
             const Promise = require('promise/setimmediate/es6-extensions');
             if (Promise !== RN_GLOBAL_OBJ.Promise) {
                 logger.warn('Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.');
+                // For message to appear
+                setTimeout(() => console.warn('Console.warn: Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.'), 0);
             }
             else {
                 logger.log('Unhandled promise rejections will be caught by Sentry.');
+                // For message to appear
+                setTimeout(() => console.log('Console.log: Unhandled promise rejections will be caught by Sentry.'), 0);
             }
         }
         catch (e) {
             // Do Nothing
             logger.warn('Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.');
+            // For message to appear
+            setTimeout(() => console.warn('Console.warn: Unhandled promise rejections will not be caught by Sentry. Read about how to fix this on our troubleshooting page.'), 0);
         }
     }
     /**

I can only see Console.log: Unhandled promise rejections will be caught by Sentry. in event breadcrumbs.

jer-sen avatar Jul 04 '23 12:07 jer-sen

@jer-sen This is likely caused by the order in which the integrations are initialized. The Breadcrumbs integration is initialized after the ReactNativeErrorHandlers .

krystofwoldrich avatar Jul 04 '23 15:07 krystofwoldrich

@krystofwoldrich ok but then in my opinion the warning is useless if we can't get it in the breadcrumbs

jer-sen avatar Jul 04 '23 16:07 jer-sen

@jer-sen It's meant for local debugging once it's set up it should not change in production.

krystofwoldrich avatar Jul 05 '23 08:07 krystofwoldrich

Ok. With dev client build (using Expo) I can see the logs.

jer-sen avatar Jul 05 '23 09:07 jer-sen