Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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)

}
}