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 hashicorp/errwrap with go1.13 native error wrapping #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/hashicorp/go-multierror

go 1.13

require github.com/hashicorp/errwrap v1.0.0
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
12 changes: 4 additions & 8 deletions prefix.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package multierror

import (
"fmt"

"github.com/hashicorp/errwrap"
)
import "fmt"

// Prefix is a helper function that will prefix some text
// to the given error. If the error is a multierror.Error, then
Expand All @@ -17,7 +13,7 @@ func Prefix(err error, prefix string) error {
return nil
}

format := fmt.Sprintf("%s {{err}}", prefix)
format := prefix + " %w"
Copy link

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.

switch err := err.(type) {
case *Error:
// Typed nils can reach here, so initialize if we are nil
Expand All @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf(format, err)
return fmt.Errorf("%s %w", prefix, err)

}
}