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

Replace pkg/errors with standard Go 1.13 error wrapping. #438

Closed
Dirbaio opened this issue May 26, 2020 · 6 comments
Closed

Replace pkg/errors with standard Go 1.13 error wrapping. #438

Dirbaio opened this issue May 26, 2020 · 6 comments
Labels
feat New feature or request.

Comments

@Dirbaio
Copy link

Dirbaio commented May 26, 2020

Describe the bug

Fosite uses pkg/errors throughout the code to find the cause of errors. The issue is that errors.Cause does not unwrap errors wrapped in Go 1.13 style (Unwrap method), just the ones in custom pkg/errors style (Cause method). The maintainers have found that unwrapping both causes breaking changes, so they (understandably) have no plans to add that. See issue.

Additionally, the pkg/errors package is in maintenance mode, as stated in their readme.

To Reproduce

One example on where this can result in uninituitive behavior:

  • From a fosite.Store method, return fosite.ErrNotFound, but somehow wrapped with a Go 1.13-compliant wrapper (maybe some extra context, maybe a library that attaches stack traces to the errors...)
  • Fosite will check if errors.Cause(err) == fosite.ErrNotFound.
  • errors.Cause(err) will not return the fosite.ErrNotFound because it can't unwrap "through" the Go1.13 wrapping. The check will fail.
  • Fosite returns the wrong oauth error to the client

Ideally fosite should use Go 1.13 wrapping, because that's what the entire ecosystem is moving to. Of course that would be a breaking change but in my opinion it's worth doing pre-1.0 while you still can?

@aeneasr
Copy link
Member

aeneasr commented May 26, 2020

Yeah, I think errors.Is is better than errors.Cause. I still want to keep pkg/errors for error creation because Go std errors don't support stack traces.

@aeneasr aeneasr added the feat New feature or request. label May 26, 2020
@Dirbaio
Copy link
Author

Dirbaio commented May 26, 2020

About stack traces: I also ran into issues with that because we're using a different stacktrace library, and it wasn't picking up fosite's.

Do you think it'd be possible to allow the user to customize which stacktracer is used?

Something like

fosite.SetStackTracer(func(err error) error {
   return errors.WithStack(err);
})

that would save that func in a global variable inside fosite, and all the places in fosite that want to wrap an error with a stack trace would call that.

Another advantage would be that users that don't want stacktraces (for performance) can do that too.

@mitar
Copy link
Contributor

mitar commented May 26, 2020

Hm, I also prefer keeping stack trace around.

I am using a custom function which inspects if something is causer or just wrapped when navigating errors and it works pretty well. Not sure why fosite would have to change here?

@aeneasr
Copy link
Member

aeneasr commented May 27, 2020

About stack traces: I also ran into issues with that because we're using a different stacktrace library, and it wasn't picking up fosite's.

Do you think it'd be possible to allow the user to customize which stacktracer is used?

Typically one would solve that with an interface / type assertion in Go and it would be expected for the downstream code to be able to handle that, not upstream.

@mitar
Copy link
Contributor

mitar commented Sep 17, 2020

So in #479 I changed that we now everywhere use errors.Is and errors.As. They use standard Go 1.13 Is and As internally, so this issue should be resolved now. (because pkg/errors is compatible with standard Is and As those calls will now traverse everything.)

Does this satisfy your needs @Dirbaio? Can you test?

@aeneasr
Copy link
Member

aeneasr commented Sep 19, 2020

I think it does! :)

@aeneasr aeneasr closed this as completed Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request.
Projects
None yet
Development

No branches or pull requests

3 participants