2016-01-29 20:53:56 +01:00
|
|
|
package multierror
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ErrorFormatFunc is a function callback that is called by Error to
|
|
|
|
// turn the list of errors into a string.
|
|
|
|
type ErrorFormatFunc func([]error) string
|
|
|
|
|
|
|
|
// ListFormatFunc is a basic formatter that outputs the number of errors
|
|
|
|
// that occurred along with a bullet point list of the errors.
|
|
|
|
func ListFormatFunc(es []error) string {
|
2018-09-25 20:19:23 +02:00
|
|
|
if len(es) == 1 {
|
|
|
|
return fmt.Sprintf("1 error occurred:\n\t* %s\n\n", es[0])
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
points := make([]string, len(es))
|
|
|
|
for i, err := range es {
|
|
|
|
points[i] = fmt.Sprintf("* %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf(
|
2018-09-25 20:19:23 +02:00
|
|
|
"%d errors occurred:\n\t%s\n\n",
|
|
|
|
len(es), strings.Join(points, "\n\t"))
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|