react-native-exception-handler
react-native-exception-handler copied to clipboard
Js exeception not caught in dev mode until first render
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
What's wrong?
"react": "^16.3.1", "react-native": "^0.55.3", "react-native-exception-handler": "^2.7.5",
Thanks
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.
Thanks @master-atul
Confirmed, it works on next interaction
Hello, is there any fix for this planned?
Not really at the moment. I am not sure how to solve this.