Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cached error deserialisation where the Throwable has a cause #418

Merged
merged 11 commits into from
Jan 21, 2019

Conversation

fractalwrench
Copy link
Contributor

Goal

When a beforeSend callback is specified, deserialisation of cached error reports fails if the exception has an additional cause. This prevents delivery of the error report to Bugsnag.

This changeset fixes #417 by altering the ErrorReader class to handle this scenario.

Design

The ErrorReader class assumed that only 1 exception could be present in an array. The implementation has therefore been altered to serialise every object in the array. The first object is considered the root Throwable, and any additional exceptions are deserialised by using initCause. This is effectively just performing the inverse of Exceptions#toStream.

Changeset

Tests

  • Ran existing mazerunner + unit tests
  • Added a unit test which loads an error report generated by an RxJava exception, and verifies that the ErrorReader deserialises it correctly.
  • Threw a throwable with a cause on an emulator with airplane mode enabled, then relaunched the app with a network connection and a beforeSend callback, confirming that an error report was delivered.

Note: none of the stack frames will be marked as in-project when delivered from a cached report that is modified in a beforeSend callback. This is independent from this bug and will be addressed in a separate PR.

Copy link
Contributor

@bengourley bengourley left a comment

Choose a reason for hiding this comment

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

A few comments

sdk/src/main/java/com/bugsnag/android/ErrorReader.java Outdated Show resolved Hide resolved
ex.setExceptionType(type);
return ex;
BugsnagException bugsnagException = new BugsnagException(errorClass, message, frames);
bugsnagException.setType(type);
Copy link
Contributor

Choose a reason for hiding this comment

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

This type thing seems odd – it exists on the collection of items before it gets serialized, but gets added to every item during serialisation. It then has to be set on the individual items when deserialised, only to be added to the collection again.

Is there something better we can do than add the seemingly useless getter/setter to the BugsnagException class?

I understand that this change just gets the job done, which might be a good enough reason to leave as is.

@fractalwrench fractalwrench merged commit 57b4915 into master Jan 21, 2019
@fractalwrench fractalwrench deleted the fix-error-deserialisation branch January 21, 2019 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with Configuration#beforeSend
2 participants