-
Notifications
You must be signed in to change notification settings - Fork 128
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 hashicorp/errwrap with go1.13 native error wrapping #60
base: main
Are you sure you want to change the base?
Conversation
The `errwrap.Wrapf()` function was deprecated in favor of native go 1.13 error wrapping in github.com/hashicorp/errwrap v1.1.0. This updates the `Prefix()` function to use native error wrapping, which removes the dependency on github.com/hashicorp/errwrap. Signed-off-by: Sebastiaan van Stijn <[email protected]>
@dnephin @mitchellh PTAL 🤗 (noticed this was deprecated when updating dependencies (moby/moby#43308), so thought I could as well try to get rid of that dependency altogether 😅) |
@mitchellh @mwhooker are there any plans to merge this PR? |
I found this issue while considering further adoption of this package vs the upstream support in Go 1.20 for wrapper errors. See |
@@ -17,7 +13,7 @@ func Prefix(err error, prefix string) error { | |||
return nil | |||
} | |||
|
|||
format := fmt.Sprintf("%s {{err}}", prefix) | |||
format := prefix + " %w" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefix
might contain %
. It must not be concatenated with formatting word.
@@ -27,11 +23,11 @@ func Prefix(err error, prefix string) error { | |||
|
|||
// Wrap each of the errors | |||
for i, e := range err.Errors { | |||
err.Errors[i] = errwrap.Wrapf(format, e) | |||
err.Errors[i] = fmt.Errorf(format, e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err.Errors[i] = fmt.Errorf(format, e) | |
err.Errors[i] = fmt.Errorf("%s %w", prefix, e) |
} | ||
|
||
return err | ||
default: | ||
return errwrap.Wrapf(format, err) | ||
return fmt.Errorf(format, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf(format, err) | |
return fmt.Errorf("%s %w", prefix, err) |
The
errwrap.Wrapf()
function was deprecated in favor of native go 1.13 errorwrapping in github.com/hashicorp/errwrap v1.1.0 (hashicorp/errwrap#9).
This updates the
Prefix()
function to use native error wrapping, which removes the dependency on github.com/hashicorp/errwrap.