a7ul / react-native-exception-handler

A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.
MIT License
1.58k stars 134 forks source link

Handling exceptions in Android release APK #51

Open harshada-bhanose opened 6 years ago

harshada-bhanose commented 6 years ago

Hello,

I am able to catch JS as well as Native exceptions in Debug APK. But the exceptions are not caught in Release APK. Can you please suggest I am missing anything? Here is my code:

import { AppRegistry, Alert } from 'react-native';
import App from './App';
import {setJSExceptionHandler, setNativeExceptionHandler} from 'react-native-exception-handler';
import RNRestart from 'react-native-restart';

const reporter = (error) => {
    console.log(error); 
};

const errorHandler = (e, isFatal) => {
    if (isFatal) {
      reporter(e);
      Alert.alert(
          'Unexpected error occurred',
          'Error: ${(isFatal) ? 'Fatal:' : ''} ${e.name} ${e.message}Please close the app and start again!',
        [{
          text: 'Restart',
          onPress: () => {
            RNRestart.Restart();
          }
        }]
      );
    } else {
      console.log(e); 
    }
  };
setJSExceptionHandler(errorHandler, true);
setNativeExceptionHandler((errorString => {
  console.log('Native exception !!!');
}), true);
a7ul commented 6 years ago

@harshada-bhanose Can you please explain what do you mean by Debug Apk . Could give me a bit more context on how you are generating the debug apk and release apk. ?

harshada-bhanose commented 6 years ago

By Debug APK I mean the unsigned app-debug.apk file generated in \android\app\build\outputs\apk\debug folder when we have the __DEV__ flag on. Release APK is the signed bundled APK generated using command ./gradlew assembleRelease

a7ul commented 6 years ago

Alright how are you simulating the errors ?

harshada-bhanose commented 6 years ago

JS exception is simulated by calling an undefined function. Native exception is simulated by a String operation causing OutOfMemory error. This one is genuine and we are trying to identify the cause.

jsu93 commented 6 years ago

Can't send data to server in setNativeExceptionHandler that caused by rn-test-exception-handler module, but did in setJSExceptionHandler that caused by undefined function call,

The two exception makers are in two buttons onPress

vsvanshi commented 6 years ago

Same case with me, I am trying to send data to server on a Native Exception, but that part is not executing. However, i have put console logs at the starting and end of the native exception handler and both statements are getting executed. Glad to give you more information, if you need

a7ul commented 6 years ago

Okay .. Do you see the native exception handler UI showing up? @vsvanshi

vsvanshi commented 6 years ago

@master-atul : Yes! Eeverything else works fine, the code written in the callback other than the api executes, the native exception handler UI also shows up. Only the api is not getting triggered.

molmutius commented 5 years ago

@jsu93 and @vsvanshi, I'm having the same issue: On a native exception I see the Error Screen and I also can log the native excpetion just fine in JS. But when I try to send it to a server afterwards nothing happens. I've made an example repo here: https://github.com/molmutius/react-native-crashtest which uses countly to send data to a server. I've also already asked the guys over at the countly slack channel and they pointed me in this direction.

@master-atul, maybe the repo I posted above helps with identifying this issue. Let me knwo, if you need support.

a7ul commented 5 years ago

@molmutius I ll check it out in the evening and lets see if we can find anything 👍

Navidhp commented 5 years ago

@master-atul I also have this problem , cannot send data to server in release mode

farahty commented 5 years ago

any update @master-atul

bartoszboruta commented 4 years ago

@master-atul still not fixed?

OmarBasem commented 3 years ago

Same issue

W1nstar commented 2 years ago

Still the same issue on 2022, somehow js code is executed on NativeErrorHandler, but any kind of http request does not work.