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

all: replace support/errors with builtin stdlib errors #2335

Open
leighmcculloch opened this issue Feb 27, 2020 · 1 comment
Open

all: replace support/errors with builtin stdlib errors #2335

leighmcculloch opened this issue Feb 27, 2020 · 1 comment

Comments

@leighmcculloch
Copy link
Member

leighmcculloch commented Feb 27, 2020

What

Replace support/errors and our use of github.com/pkg/errors with using the builtin stdlib errors wrapping and unwrapping functions that are available since Go 1.13.

Why

Now that #2325 is merged and we only support Go 1.13 and 1.14 we now have the capability to use features that were added in Go 1.13. The stdlib got new errors functions that support natively wrapping and unwrapping errors. We should use them to make our code more friendly to generic Go code. Even the original author of pkg/errors has stated he no longer uses the packages and this extra layer distances us from writing code that is understandable by an average Go developer because our errors just work that little bit different and causes our errors to behave in subtly different ways to native errors.

Concerns

The pkg/errors errors give us stack traces with our errors, while stdlib errors still do not. This has been an area lacking consensus and so I doubt stdlib errors will gain stack traces soon. We shouldn't do this assuming stack traces might show up in a future release. If this is something we find extremely valuable we should probably not do this.

@leighmcculloch leighmcculloch changed the title Replace support/errors with builtin stdlib errors all: replace support/errors with builtin stdlib errors Jun 24, 2021
@mitar
Copy link

mitar commented Oct 9, 2023

Shameless plug: you can switch it to drop-in replacement gitlab.com/tozd/go/errors. It fixes many issues, is maintained, and supports modern Go's error patterns (sentinel errors, %w formatting, joined errors, etc.). It also provides some nice utility functions and structured details so that it is easy to extract dynamic data out of errors (instead of trying to get them out of formatted strings). Has improved error formatting and JSON marshaling of errors. It is interoperable with other errors packages and does not require a dependency on itself to extract data (e.g., stack trace) from errors.

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

No branches or pull requests

2 participants