You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
leighmcculloch
changed the title
Replace support/errors with builtin stdlib errors
all: replace support/errors with builtin stdlib errors
Jun 24, 2021
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.
What
Replace
support/errors
and our use ofgithub.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.
The text was updated successfully, but these errors were encountered: