-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: Go 2: adopt Cause and Wrap from github.com/pkg/errors #25675
Comments
I think we could simplify the https://github.com/pkg/errors API a little further and add two new functions only: func Cause(err error) error
func Wrap(err error, message string) error
- func Errorf(format string, args ...interface{}) error
- func WithMessage(err error, message string) error
- func WithStack(err error) error
- func Wrapf(err error, format string, args ...interface{}) error
func main() {
if debug {
errors.CaptureStackTraces = true // false by default
}
}
|
As another point in the design space, a package like https://github.com/pkg/errors but with the simpler API is https://godoc.org/github.com/samsarahq/go/oops. |
It's a good package, but what's the argument for bringing it into the standard library? Bear in mind https://golang.org/doc/faq#x_in_std . |
One motivation for standardizing is uniform handling of well-known errors. For example, wrapping |
@ianlancetaylor argument for bringing it into the standard library is just standardization of error context across the Go ecosystem. Not everyone uses github.com/pkg/errors as of now obviously. Example: |
Thanks. Standardization of error context is a big concept, and I don't think that the errors package addresses all aspects of it. For example, see https://commandcenter.blogspot.com/2017/12/error-handling-in-upspin.html for some additional ideas in this space. |
I would also like to see standardization around some common optional interfaces, like |
I like the approach in this blog post, Failure Is Your Domain. The author emphasizes the importance of "owning" your failure modes, but I think that some of the functions mentioned in the article would be good candidates for standard library inclusion. |
I'd be glad to see standard |
Is there a reason why this is a |
@deanveloper, because Go isn't a language where we just keep adding stuff all the time. We prefer to think about the end goal and the minimal set of things that would interact well. Once we add stuff, we can't remove it soon or easily, and it might not be what we want in the end. So we prefer to go slowly, even if that's boring and frustrating at times. |
Closing in favor of the discussion at https://github.com/golang/go/wiki/Go2ErrorValuesFeedback . I have added this issue to that page. |
Is there anyone else who'd like to see https://github.com/pkg/errors (or similar) being adopted in Go 2.0?
Forked from #21161 (comment).
Example:
Alternative one-liner example, since errors.Wrap() returns
nil
onnil
error:The text was updated successfully, but these errors were encountered: