Skip to content

Instantly share code, notes, and snippets.

@ospfranco
Created July 27, 2020 14:31
Show Gist options
  • Save ospfranco/f11b8e01615279ba7a006c5dcf72fccb to your computer and use it in GitHub Desktop.
Save ospfranco/f11b8e01615279ba7a006c5dcf72fccb to your computer and use it in GitHub Desktop.
Attach Javascript stack to Crashlytics
// If you are using crashlytics and you cannot update to the latest versions of react-native-firebase (or need sourcemaps which is doesn't support) adding middleware to the error handling can at least provide you with an error stack
//Define an error handler to upload thet stack to crashlytics
const defaultHandler = global.ErrorUtils.getGlobalHandler()
const crashlytics = firebase.crashlytics()
global.ErrorUtils.setGlobalHandler((...args) => {
const error = args[0] || 'Unknown'
//console.log('Crashlytics error sent', error);
if (error instanceof Error) {
crashlytics.setStringValue('stack', `${error.stack}`)
crashlytics.setStringValue('message', `${error.message}`)
crashlytics.recordError(0, `RN Fatal: ${error.message}`)
} else {
// Have never gotten this log so far. Might not be necessary.
crashlytics.recordError(0, `RN Fatal: ${error}`)
}
crashlytics.log(error.message);
defaultHandler.apply(this, args);
//force the native crash
crashlytics.crash();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment