-
Notifications
You must be signed in to change notification settings - Fork 205
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
Conversation
…hrowable also has a cause
Java exceptions can have multiple throwables (e.g. a root throwable, and the 'cause' which triggered the exception). The ErrorReader class did not previously handle this case, which led to a failure to send cached error reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments
ex.setExceptionType(type); | ||
return ex; | ||
BugsnagException bugsnagException = new BugsnagException(errorClass, message, frames); | ||
bugsnagException.setType(type); |
There was a problem hiding this comment.
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.
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 rootThrowable
, and any additional exceptions are deserialised by usinginitCause
. This is effectively just performing the inverse ofExceptions#toStream
.Changeset
Tests
ErrorReader
deserialises it correctly.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.