question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throwing in a Results listener callback crashes the app

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kraenhansencommented, Dec 20, 2019

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.

0reactions
knethcommented, Nov 18, 2021

We will document the behaviour until we have a clear idea of how to solve it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to have a callback for when a crash occurred, while using ...
Try creating an UncaughtExceptionHandler and use Custom Key(s) to store the information you want to be associated with your crash report.
Read more >
Detect and diagnose crashes - Android Developers
An app that is written using Java or Kotlin crashes if it throws an unhandled exception, ... handleCallback(Handler.java:751) at android.os.
Read more >
App Center Crashes for React Native - Microsoft Learn
In order for your Crash.setListener methods to work as expected you need to check if your application configured properly. Open the project's ...
Read more >
Let It Crash: Best Practices for Handling Node.js Errors on ...
At last, we arrive at higher-level error types: the error events thrown by JavaScript itself. When a JavaScript error is not properly handled, ......
Read more >
Events | Node.js v19.3.0 Documentation
To guard against crashing the Node.js process the domain module can be used. ... the 'newListener' callback are inserted before the listener that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found