Command line client for Write.as https://write.as/apps/cli
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
962 B

  1. package multierror
  2. // Append is a helper function that will append more errors
  3. // onto an Error in order to create a larger multi-error.
  4. //
  5. // If err is not a multierror.Error, then it will be turned into
  6. // one. If any of the errs are multierr.Error, they will be flattened
  7. // one level into err.
  8. func Append(err error, errs ...error) *Error {
  9. switch err := err.(type) {
  10. case *Error:
  11. // Typed nils can reach here, so initialize if we are nil
  12. if err == nil {
  13. err = new(Error)
  14. }
  15. // Go through each error and flatten
  16. for _, e := range errs {
  17. switch e := e.(type) {
  18. case *Error:
  19. if e != nil {
  20. err.Errors = append(err.Errors, e.Errors...)
  21. }
  22. default:
  23. if e != nil {
  24. err.Errors = append(err.Errors, e)
  25. }
  26. }
  27. }
  28. return err
  29. default:
  30. newErrs := make([]error, 0, len(errs)+1)
  31. if err != nil {
  32. newErrs = append(newErrs, err)
  33. }
  34. newErrs = append(newErrs, errs...)
  35. return Append(&Error{}, newErrs...)
  36. }
  37. }