Command line client for Write.as https://write.as/apps/cli
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637
  1. package multierror
  2. import (
  3. "fmt"
  4. "github.com/hashicorp/errwrap"
  5. )
  6. // Prefix is a helper function that will prefix some text
  7. // to the given error. If the error is a multierror.Error, then
  8. // it will be prefixed to each wrapped error.
  9. //
  10. // This is useful to use when appending multiple multierrors
  11. // together in order to give better scoping.
  12. func Prefix(err error, prefix string) error {
  13. if err == nil {
  14. return nil
  15. }
  16. format := fmt.Sprintf("%s {{err}}", prefix)
  17. switch err := err.(type) {
  18. case *Error:
  19. // Typed nils can reach here, so initialize if we are nil
  20. if err == nil {
  21. err = new(Error)
  22. }
  23. // Wrap each of the errors
  24. for i, e := range err.Errors {
  25. err.Errors[i] = errwrap.Wrapf(format, e)
  26. }
  27. return err
  28. default:
  29. return errwrap.Wrapf(format, err)
  30. }
  31. }