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.
33 lines
637 B
33 lines
637 B
// Package multierror wraps a slice of errors and implements the error interface.
|
|
// This can be used to collect a bunch of errors (such as during form validation)
|
|
// and then return them all together as a single error. To see usage examples
|
|
// refer to the unit tests.
|
|
package multierror
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Error []error
|
|
|
|
func (me Error) Error() string {
|
|
if me == nil {
|
|
return ""
|
|
}
|
|
|
|
strs := make([]string, len(me))
|
|
for i, err := range me {
|
|
strs[i] = fmt.Sprintf("[%d] %v", i, err)
|
|
}
|
|
return strings.Join(strs, " ")
|
|
}
|
|
|
|
func (me Error) AsError() error {
|
|
if len([]error(me)) <= 0 {
|
|
return nil
|
|
}
|
|
|
|
return me
|
|
}
|