Open kraenhansen opened 4 years ago
It might be out of the scope of Realm as a library to make the decision to swallow exceptions. Other options exist within the React Native framework:
ErrorUtils.setGlobalHandler()
- https://stackoverflow.com/questions/30918349/how-to-catch-uncaught-exception-globally-in-react-nativeNativeModules.ExceptionsManager
- https://stackoverflow.com/questions/44774247/how-to-disable-red-screen-in-debug-modeI don't consider the current behaviour as a bug.
Realm should never crash a React Native app.
I don't consider the current behaviour as a bug.
It might not be straight forward to understand or fix, but let's not kid ourselves: Of cause it's a bug when a library breaks invariants of the environment, namely "JS code might throw unhandled exceptions, but it will never crash the process running the JS code". It is super unexpected behavior on our part.
I agree that the correct behaviour is that a JS exception is thrown: a raw C++ exception is definitely not adding any value for the app developer.
After 6 months I still don't consider it a bug. Throwing an exception inside a callback is not best practise. Moreover, callbacks should have a try
/catch
and handle errors gracefully. We should document it clearly in our API documentation that we except users to handle errors inside the listener.
@kneth is the error actually thrown in JS-context?
If the error doesn't currently show up as a "red error screen" in React Native development mode (that's how I read the initial issue), it sounds like the app crashed at a level where developers can't catch
the error.
We will document the behaviour until we have a clear idea of how to solve it.
Goals
Realm should never crash a React Native app.
I suspect that we need to tell the JSCore engine that an unhandled exception happened during the execution of the callback.
I suspect this also happens if the error is thrown from other callbacks that we call from C++, therefore the following issues probably share the same root cause: https://github.com/realm/realm-js/issues/2029, https://github.com/realm/realm-js/issues/1439, https://github.com/realm/realm-js/issues/2233.
Expected Results
When an error is thrown from a callback added as a listener on a
Results
object, I expect an uncaught exception to be handled (resulting in a black screen with a red top-bar while in development mode).Actual Results
When an error is thrown from a callback added as a listener on a
Results
object, the app crashes!Steps to Reproduce & Code Sample
Version of Realm and Tooling