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

Make eventFromException handle recursively wrapped errors #176

Closed
inesmersak opened this issue Mar 4, 2020 · 1 comment · Fixed by #185
Closed

Make eventFromException handle recursively wrapped errors #176

inesmersak opened this issue Mar 4, 2020 · 1 comment · Fixed by #185
Milestone

Comments

@inesmersak
Copy link

Currently, client.eventFromException only calls the Cause method on the exception once.

Using github.com/pkg/errors, if we use the errors.Wrap function to wrap our error (let's say of type TestError), this gives us the following chain:
errors.WithStack -> errors.WithMessage -> TestError
and since the Cause method returns the direct cause, not the underlying one, we end up with type errors.WithMessage being reported to Sentry. (Instead of TestError.)

I believe the underlying cause should be reported to sentry, i.e. eventFromException should determine cause in the same way github.com/pingcap/errors and github.com/pkg/errors do (both call the Cause method repeatedly, the first recursively, the second iteratively).

The proposed change of this part:

for exception != nil {
	if ex, ok := exception.(interface{ Cause() error }); ok {
		exception = ex.Cause()
	} else {
		break
	}
}
cause := exception

Let me know what you think and whether I can open a PR to fix this :)

@rhcarvalho rhcarvalho added this to the v0.6.0 milestone Mar 17, 2020
@rhcarvalho
Copy link
Contributor

Hi @inesmersak! Thanks for the report, I acknowledge it.

A solution needs to take into account:

  • Careful unwrapping / cause traversal for compatibility with Support for stack frames from xerrors. #137.
  • Careful handling of nil values (see handling "err.Cause() == nil" case #160).
  • Avoid infinite loop.
  • We can do better than github.com/pingcap/errors.Cause and github.com/pkg/errors.Cause because instead of reporting a single error we can report all errors in the chain.

Pending a clarification on the Sentry API for how best to implement the last point. There are at least two possibilities:

  1. Multiple exceptions (errors): https://github.com/getsentry/relay/blob/master/relay-general/src/protocol/event.rs#L320-L324
  2. Multiple values in single exception (error): https://github.com/getsentry/relay/blob/master/relay-general/src/protocol/exception.rs#L4-L41

I'm reaching out for help from other folks in the team to decide on the above.

Since there is some ambiguity here, please let's flesh out the details first before working on a PR.

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 a pull request may close this issue.

3 participants