3 // Append is a helper function that will append more errors
4 // onto an Error in order to create a larger multi-error.
6 // If err is not a multierror.Error, then it will be turned into
7 // one. If any of the errs are multierr.Error, they will be flattened
9 func Append(err error, errs ...error) *Error {
10 switch err := err.(type) {
12 // Typed nils can reach here, so initialize if we are nil
17 // Go through each error and flatten
18 for _, e := range errs {
19 switch e := e.(type) {
22 err.Errors = append(err.Errors, e.Errors...)
26 err.Errors = append(err.Errors, e)
33 newErrs := make([]error, 0, len(errs)+1)
35 newErrs = append(newErrs, err)
37 newErrs = append(newErrs, errs...)
39 return Append(&Error{}, newErrs...)