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

Support unwrapping error #193

Closed
jaycetde opened this issue Sep 21, 2022 · 3 comments · Fixed by #194
Closed

Support unwrapping error #193

jaycetde opened this issue Sep 21, 2022 · 3 comments · Fixed by #194
Labels
feature request Request for a new feature released This feature/bug fix has been released

Comments

@jaycetde
Copy link
Contributor

jaycetde commented Sep 21, 2022

Description

Support unwrapping errors using errors.Unwrap from standard library. Supporting unwrap will also allow errors.Is to work:

import (
	"errors"
	bserrors "github.com/bugsnag/bugsnag-go/v2/errors"
)

var MyErr = errors.New("my error")

wrappedErr := bserrors.Errorf("wrapped: %w", MyErr)

if errors.Is(wrappedErr, MyErr) {
  // Custom logic here
}

Describe the solution you'd like
Add the following to errors/error.go:

func (err *Error) Unwrap() error {
	return err.Err
}

or possibly:

func (err *Error) Unwrap() error {
	return errors.Unwrap(err.Err)
}
@luke-belton
Copy link
Member

Hi @jaycetde - thanks for raising this. We've added an item to our product roadmap to work on this in the future. I don't currently have an ETA, but we'll keep this thread updated 👍

@luke-belton luke-belton added feature request Request for a new feature backlog We hope to fix this feature/bug in the future labels Oct 4, 2022
@luke-belton
Copy link
Member

Hi @jaycetde - just wanted to follow up on this to say we're unlikely to prioritise this work in the immediate future, but we would be willing to accept a contribution if you're interested. We'd want to go for your second proposed solution, i.e.

func (err *Error) Unwrap() error {
	return errors.Unwrap(err.Err)
}

The solution would also need to have a simple test to cover it 👍

@luke-belton
Copy link
Member

Hi @jaycetde - thanks again for this, support for this was released in v1.9.1 of bugsnag-go 👍

@luke-belton luke-belton added released This feature/bug fix has been released and removed backlog We hope to fix this feature/bug in the future labels Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature released This feature/bug fix has been released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants