Can't trigger Native crashes with expo-sentry?

Problem: can’t seem to trigger native crashes with expo-sentry

Managed workflow

Eas cli version >= 0.45.1

What I’ve tried/reproducible code:

  1. (set up app config and config plugin based on docs)

  2. Sentry.init setup:

Sentry.init({
  dsn: "XXX",
  enableInExpoDevelopment: true,
  debug: true, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
  environment: `XXX`,
});
  1. Function to trigger crash:
import * as ExpoSentry from "sentry-expo";

cons handlePressCrash = () => {
     ExpoSentry.Native.nativeCrash();
}

What happens/behaviour:

While testing in development:
I can see Errors that are being thrown (when I run a function to throw new Error(), but nothing happens when I try and crash the app using the function above. I’ve tested on an iOS simulator and an actual android device. I’ve also console logged items within the nativeCrash function (in library code) and it seems to be called, but I don’t see the app crashing.

It notifies you of exceptions or errors that your users run into while using your app, and organizes them for you on a web dashboard. Reported exceptions include stacktraces, device info, version, and other relevant context automatically; you can also provide additional context that is specific to your application, like the current route and user id.

@arohan I am seeing the same behavior. I have recently upgraded to sdk 45 and my app crashes however nothing is reported back to Sentry dashboard :confused:

Hi @arohan, @larson3 and @bkamrani

Try this as a workaround, at least on Android. The following crashes reliably for me, and it’s a native crash:

import { useState } from 'react';
import { StatusBar } from 'expo-status-bar';
import { Button, StyleSheet, Text, View } from 'react-native';

export default function App() {
  const [pressed, setPressed] = useState(false);

  const onPress = () => {
    setPressed(!pressed);
  };

  return (
    <View style={styles.container}>
      <Button title="Crash!" onPress={onPress} />
      {pressed && <Text style={{width: "crash!"}}>Did I crash?</Text>}
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

I have not tried it with Sentry, though.

05-11 01:16:27.049 25915 25915 E AndroidRuntime: FATAL EXCEPTION: main
05-11 01:16:27.049 25915 25915 E AndroidRuntime: Process: host.exp.exponent, PID: 25915
05-11 01:16:27.049 25915 25915 E AndroidRuntime: java.lang.IllegalStateException: abi45_0_0.com.facebook.react.uimanager.IllegalViewOperationException: Trying to add unknown view tag: 889
05-11 01:16:27.049 25915 25915 E AndroidRuntime:  detail: View tag:875 View Type:class abi45_0_0.com.facebook.react.views.view.ReactViewGroup
05-11 01:16:27.049 25915 25915 E AndroidRuntime:   children(2): [
05-11 01:16:27.049 25915 25915 E AndroidRuntime: 867,873,
05-11 01:16:27.049 25915 25915 E AndroidRuntime:  ],
05-11 01:16:27.049 25915 25915 E AndroidRuntime:   viewsToAdd(1): [
05-11 01:16:27.049 25915 25915 E AndroidRuntime: [2,889],
05-11 01:16:27.049 25915 25915 E AndroidRuntime:  ],
05-11 01:16:27.049 25915 25915 E AndroidRuntime:
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.bridge.ReactContext.handleException(ReactContext.java:6)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:2)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:7)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:1)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:947)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.view.Choreographer.doFrame(Choreographer.java:693)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:873)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:214)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7050)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
05-11 01:16:27.049 25915 25915 E AndroidRuntime: Caused by: abi45_0_0.com.facebook.react.uimanager.IllegalViewOperationException: Trying to add unknown view tag: 889
05-11 01:16:27.049 25915 25915 E AndroidRuntime:  detail: View tag:875 View Type:class abi45_0_0.com.facebook.react.views.view.ReactViewGroup
05-11 01:16:27.049 25915 25915 E AndroidRuntime:   children(2): [
05-11 01:16:27.049 25915 25915 E AndroidRuntime: 867,873,
05-11 01:16:27.049 25915 25915 E AndroidRuntime:  ],
05-11 01:16:27.049 25915 25915 E AndroidRuntime:   viewsToAdd(1): [
05-11 01:16:27.049 25915 25915 E AndroidRuntime: [2,889],
05-11 01:16:27.049 25915 25915 E AndroidRuntime:  ],
05-11 01:16:27.049 25915 25915 E AndroidRuntime:
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:35)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.host.exp.exponent.modules.api.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager.manageChildren(ReanimatedNativeHierarchyManager.java:2)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:1)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:19)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:10)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:1)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:6)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        at abi45_0_0.com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:1)
05-11 01:16:27.049 25915 25915 E AndroidRuntime:        ... 13 more

[FIX]

Turns out, this error was only happening in my local environment (while developing). When deployed to my staging/test environment (I built a standalone binary with EAS build), everything seemed to work fine. This is a little misleading / not specified in the docs - I expected it to work in development because I set enableInExpoDevelopment: true when initialising Sentry (see initial post).

I can simulate crashes both from sentry-expo as well as from @sentry/react-native (see code below):

Working Code snippet (pasted verbatim):

import * as ExpoSentry from "sentry-expo";
import * as RNSentry from "@sentry/react-native";
...
 <Button
          title="Trigger Error"
          color={colours.ERROR}
          onPress={() => {
            throw new Error(`Error ${new Date()}`);
          }}
        />
        <Button
          title="Crash @sentry/react-native"
          color={colours.ERROR_DARK}
          onPress={() => {
            RNSentry.nativeCrash();
          }}
          containerStyle={{ marginVertical: Size.SMALL }}
        />
        <Button
          title="Crash sentry-expo"
          color={colours.ERROR_DARK}
          onPress={() => {
            ExpoSentry.Native.nativeCrash();
          }}
        />

Screenshot:

Log in Sentry:

Thanks @wodin for the alternative suggestion.

2 Likes