Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

fix: make JavaScriptException inherit from BugsnagException #393

Merged
merged 2 commits into from
Aug 15, 2019

Conversation

fractalwrench
Copy link
Contributor

Goal

As part of bugsnag/bugsnag-android#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.

Copy link
Contributor

@tomlongridge tomlongridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -27,7 +29,7 @@
private ReactContext reactContext;
private String libraryVersion;
private String bugsnagAndroidVersion;
static final Logger logger = Logger.getLogger("bugsnag-react-native");
public static final Logger logger = Logger.getLogger("bugsnag-react-native");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScriptException needs to be in a different package to access package-private methods in BugsnagException, which meant it could no longer access this field.

@fractalwrench fractalwrench merged commit 532009a into master Aug 15, 2019
@fractalwrench fractalwrench deleted the alter-android-serialisation branch August 15, 2019 15:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants