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

Js exeception not caught in dev mode until first render

Open dowmeister opened this issue 6 years ago • 4 comments

Hi,

i'm trying to integrate this module

In index.js (main entrypoint)

import {
    AppRegistry
} from 'react-native';
import App from './App';

import {
    Alert
} from 'react-native';
import {
    setJSExceptionHandler,
    getJSExceptionHandler
} from 'react-native-exception-handler';
import {
    setNativeExceptionHandler
} from 'react-native-exception-handler';

const errorHandler = (e, isFatal) => {

    console.log('------------------- JS HANDLER ------------------');
console.log('------------------- CUSTOM JS HANDLER ------------------');
    console.log(error);

    if (isFatal) {
        Alert.alert(
            'Unexpected error occurred',
            `
          Error: ${(isFatal) ? 'Fatal:' : ''} ${e.name} ${e.message}
  
          We will need to restart the app.
          `, [{
                text: 'Restart',
                onPress: () => {
                    //RNRestart.Restart();
                }
            }]
        );
    } else {
        console.log(e); // So that we can see it in the ADB logs in case of Android if needed
    }
};

const setNativeHandler = (exceptionString) => {

    console.log('------------------- NATIVE HANDLER ------------------');
    console.log(exceptionString);
};

console.log('------------------- JS HANDLER ------------------');
console.log('Entering exception handling');

setJSExceptionHandler(errorHandler, true);

setNativeExceptionHandler(setNativeHandler, false);

AppRegistry.registerComponent('TruckyV2', () => App);

In adb log i see

------------------- JS HANDLER ------------------ Entering exception handling

Don't see ------------------- CUSTOM JS HANDLER ------------------

In Home.js constructor (called from App), i've added this.test() to force fire error, continue to see the RN default red screeen

screenshot_1525254292

What's wrong?

"react": "^16.3.1", "react-native": "^0.55.3", "react-native-exception-handler": "^2.7.5",

Thanks

dowmeister avatar May 02 '18 09:05 dowmeister

Hi @shardick Yes, The exception handler doesnt catch the error on first render. Its an issue being tracked here https://github.com/master-atul/react-native-exception-handler/issues/36. The issue is that the js exception handler module doesn't seem to fire before first render.

The issue occurs only till first render of the app.

You can try moving the this.test() call to a button click maybe to test it.

In the meanwhile I ll mark this as a bug and track it here.

a7ul avatar May 02 '18 10:05 a7ul

Thanks @master-atul

Confirmed, it works on next interaction

screenshot_1525264285

dowmeister avatar May 02 '18 12:05 dowmeister

Hello, is there any fix for this planned?

aks1994 avatar Feb 07 '19 08:02 aks1994

Not really at the moment. I am not sure how to solve this.

a7ul avatar Feb 07 '19 12:02 a7ul