Throwing in a Results listener callback crashes the app
See original GitHub issueGoals
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
// App.js
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import Realm from 'realm'
export default class App extends Component {
componentDidMount() {
const realm = new Realm({
schema: [{
name: "Singleton",
properties: { value: "string" },
}],
});
realm.objects("Singleton").addListener(() => {
throw new Error("Change happened!");
});
}
render() {
return <View><Text>App loaded ...</Text></View>;
}
}
Version of Realm and Tooling
- Realm JS SDK Version: 2.6.0
- Node or React Native: React Native (confirmed on iOS)
- Client OS & Version: N/A
- Which debugger for React Native: None
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
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.
We will document the behaviour until we have a clear idea of how to solve it.