6 "github.com/hashicorp/errwrap"
9 // Prefix is a helper function that will prefix some text
10 // to the given error. If the error is a multierror.Error, then
11 // it will be prefixed to each wrapped error.
13 // This is useful to use when appending multiple multierrors
14 // together in order to give better scoping.
15 func Prefix(err error, prefix string) error {
20 format := fmt.Sprintf("%s {{err}}", prefix)
21 switch err := err.(type) {
23 // Typed nils can reach here, so initialize if we are nil
28 // Wrap each of the errors
29 for i, e := range err.Errors {
30 err.Errors[i] = errwrap.Wrapf(format, e)
35 return errwrap.Wrapf(format, err)