You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[JS] JS API for global handling of unhandled exceptions #1194
The API I envision is similar to window.onerror but not necessarily the same. This would allow us to make RCTExceptionsManager.reportUnhandledException a lot smaller (we'd move much of the code into JS to keep the current behavior) and make it easier to do custom error handling.
changed the title [-]JS API for global handling of unhandled exceptions[/-][+][JS] JS API for global handling of unhandled exceptions[/+]on May 30, 2015
@ide Hi. I would very much appreciate such an API. In the mean time is there a way to prevent an production app from crashing on any random JavaScript exception?
'setGlobalHandler' would overwrite a lot of the RN behaviour (eg. RedBox in development). Understanding that we could just monkey patch globalHandler, the "" seems alarming. So maybe an API like addGlobalHandler, so that we could add custom handler without breaking the default behaviour and and without messing with "internal" variables ? @ide@satya164
Reacted by Chris Schlensker, Jason Merino and Fundebug
In production mode I call setGlobalHandler with my own handler, which does the two things listed above -- logging to sentry & reloading the bridge. Seems to work just fine.
The ErrorUtils.setGlobalHandler works great when the app's process is attached to the debugger (regardless if in debug / release bundle): I see a red screen with the error message, and my own custom handler is called fine.
But how do I handle errors for production apps, where a debugger won't be attached? When a debugger isn't attached and a crash occurs, the app doesn't show a red screen and just closes the app and goes to the home screen. In this case, my custom handler isn't called at all.
(Specifically describing the flow for iOS bundled app here)
Hi, I'm fairly new to both RN and javascript. I've put the following into my code... It catches errors and warnings in an array before reporting them as normal to the console.
It sits at the top of my main.js file. It seems to work, but is this a terrible idea?
I ended up trapping console.log, console.info, console.warn and console.error and writing the data to an in-memory buffer that I can view in my app. I also send error and warn messages to a server that records the data so I can see error from my clients in one central place.
Activity
[-]JS API for global handling of unhandled exceptions[/-][+][JS] JS API for global handling of unhandled exceptions[/+]d-vine commentedon Jun 11, 2015
@ide Hi. I would very much appreciate such an API. In the mean time is there a way to prevent an production app from crashing on any random JavaScript exception?
JoeStanton commentedon Jul 20, 2015
This would be great for adding something like Bugsnag to report exceptions when apps are in production.
Edit: In fact, I think
ErrorUtils.setGlobalHandler((err, isFatal) => { ... });might do the job here.richardgill commentedon Jul 30, 2015
We're looking to log something anytime there is an error, so we can catch bugs early. This would be very useful.
despairblue commentedon Sep 1, 2015
would be definitely useful!:+1:
sjmueller commentedon Sep 24, 2015
@ide, what is the current recommended approach (or hack) for custom handling of global errors?
ide commentedon Sep 24, 2015
You could either hook into the native layer or monkeypatch the JS ExceptionsManager.
mkonicek commentedon Dec 15, 2015
See
ErrorUtils.setGlobalHandler: https://github.com/facebook/react-native/blob/master/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js#L87atticoos commentedon Dec 15, 2015
Is it a bad idea to set my own global error handler?
My scenario was to
qbig commentedon Jan 26, 2016
Hi @ajwhite. Any luck completing the 2 points you mentioned?
qbig commentedon Jan 27, 2016
Here: https://github.com/facebook/react-native/blob/d33b554f5d4bb7856cf2fc21175bab23d8225fe4/packager/react-packager/src/Resolver/polyfills/error-guard.js
'setGlobalHandler' would overwrite a lot of the RN behaviour (eg. RedBox in development). Understanding that we could just monkey patch globalHandler, the "" seems alarming. So maybe an API like addGlobalHandler, so that we could add custom handler without breaking the default behaviour and and without messing with "internal" variables ? @ide @satya164
atticoos commentedon Jan 27, 2016
In production mode I call
setGlobalHandlerwith my own handler, which does the two things listed above -- logging to sentry & reloading the bridge. Seems to work just fine.qbig commentedon Jan 27, 2016
@ajwhite Cool. How do you reload the bridge? Would really appreciate it if you could share a gist or something.
qbig commentedon Jan 27, 2016
@ajwhite And you have a DEV check I suppose?
9 remaining items
add getter as public api for ErrorUtils._globalHandler
jsierles commentedon Mar 20, 2016
This issue appears to have been solved by #5575. Closing this issue out for now.
jlo1 commentedon Apr 12, 2016
The
ErrorUtils.setGlobalHandlerworks great when the app's process is attached to the debugger (regardless if in debug / release bundle): I see a red screen with the error message, and my own custom handler is called fine.But how do I handle errors for production apps, where a debugger won't be attached? When a debugger isn't attached and a crash occurs, the app doesn't show a red screen and just closes the app and goes to the home screen. In this case, my custom handler isn't called at all.
(Specifically describing the flow for iOS bundled app here)
npomfret commentedon Jun 3, 2016
Hi, I'm fairly new to both RN and javascript. I've put the following into my code... It catches errors and warnings in an array before reporting them as normal to the console.
It sits at the top of my main.js file. It seems to work, but is this a terrible idea?
I then periodically clear the array and send the data to some reporting system.
GeoffreyPlitt commentedon Aug 26, 2016
@jlo1 Did you ever find a solution for non-debug mode?
antoinerousseau commentedon Aug 27, 2016
I'm pretty sure that
global.ErrorUtils.setGlobalHandlerworks in production mode too on Android, fyi.GeoffreyPlitt commentedon Aug 28, 2016
What about iOS? Is there a platform-agnostic way to do this?
npomfret commentedon Aug 29, 2016
I ended up trapping console.log, console.info, console.warn and console.error and writing the data to an in-memory buffer that I can view in my app. I also send error and warn messages to a server that records the data so I can see error from my clients in one central place.
nsyujian commentedon May 31, 2018