Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-377

Throwing in a Results listener callback crashes the app

      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

      // 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

            Assignee:
            kraen.hansen@mongodb.com Kræn Hansen
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: