react-native-exception-handler icon indicating copy to clipboard operation
react-native-exception-handler copied to clipboard

Handling exceptions in Android release APK

Open harshada-bhanose opened this issue 6 years ago • 15 comments

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);

harshada-bhanose avatar Apr 19 '18 09:04 harshada-bhanose

@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. ?

a7ul avatar Apr 19 '18 13:04 a7ul

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

harshada-bhanose avatar Apr 19 '18 16:04 harshada-bhanose

Alright how are you simulating the errors ?

a7ul avatar Apr 19 '18 17:04 a7ul

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.

harshada-bhanose avatar Apr 19 '18 17:04 harshada-bhanose

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

jsu93 avatar Apr 30 '18 10:04 jsu93

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

vsvanshi avatar Aug 22 '18 09:08 vsvanshi

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

a7ul avatar Aug 24 '18 18:08 a7ul

@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.

vsvanshi avatar Aug 25 '18 05:08 vsvanshi

@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.

molmutius avatar Nov 30 '18 05:11 molmutius

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

a7ul avatar Nov 30 '18 08:11 a7ul

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

Navidhp avatar Feb 05 '19 16:02 Navidhp

any update @master-atul

farahty avatar Apr 11 '19 05:04 farahty

@master-atul still not fixed?

bartoszboruta avatar Dec 12 '19 14:12 bartoszboruta

Same issue

OmarBasem avatar Jul 02 '21 07:07 OmarBasem

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

W1nstar avatar Aug 03 '22 09:08 W1nstar