bugsnag / bugsnag-react-native

Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
https://docs.bugsnag.com/platforms/react-native
MIT License
370 stars 121 forks source link

fix: make JavaScriptException inherit from BugsnagException #393

Closed fractalwrench closed 5 years ago

fractalwrench commented 5 years ago

Goal

As part of https://github.com/bugsnag/bugsnag-android/pull/553 the way exceptions are serialised in bugsnag-android was altered. This was to allow the exception name/message to be altered after a BugsnagException object has been constructed.

As part of this change, the exception serialisation was altered so that when building an error, all Throwable objects must be wrapped in a BugsnagException if they are not already of that type. This meant that JavaScriptException#toStream() was not invoked when serialising an error report, leading to the name being serialised as com.bugsnag.JavaScriptException, rather than the name of the JS error.

This changeset alters JavaScriptException to inherit BugsnagException, meaning that it is not wrapped in a BugsnagException, and that its custom toStream implementation will be invoked and the JS error serialised correctly.

Tests

Tested manually in the example app and confirmed that ReferenceError was the error class and the correct stacktrace was collected.

Additional unit test coverage has also been added in the Android PR.