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: wrap error messages in fmt.Errorf #438

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from

Conversation

jamescoombs-soda
Copy link

use %w instead of %v when nesting error messages so they can be properly unwrapped by upstream callers.

I've run into a problem where I'm unable to use errors.Is() in my tooling to help properly respond to errors coming out of oidc. The primary use case is checking for context.Canceled, but I'm sure there are others.

Note: I believe %w was introduced in Go version 1.13, so this change isn't friendly to users who use a 5 year old Go version but keep their packages up to date. In any case, it's possible this package already requires a higher Go version than that.

use %w instead of %v when nesting error messages so they can be
properly unwrapped by upstream callers
@ericchiang
Copy link
Collaborator

Thanks for the PR!

I'm against using wrapped errors overly-broadly like this without making it part of the API contract. At the very least, there needs to be an associated test, since users might depend on a method returning a specific error type.

You mentioned checking for context.Canceled. Do you have an example? Particularly with the new "Cause" API, there are other ways of handling context cancelation.

https://pkg.go.dev/context#Cause

Do you have a sense of what the godoc changes would be before we move forward with the code itself?

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.

2 participants