]>
Commit | Line | Data |
---|---|---|
bae9f6d2 JC |
1 | package multierror |
2 | ||
3 | import ( | |
4 | "fmt" | |
5 | "strings" | |
6 | ) | |
7 | ||
8 | // ErrorFormatFunc is a function callback that is called by Error to | |
9 | // turn the list of errors into a string. | |
10 | type ErrorFormatFunc func([]error) string | |
11 | ||
12 | // ListFormatFunc is a basic formatter that outputs the number of errors | |
13 | // that occurred along with a bullet point list of the errors. | |
14 | func ListFormatFunc(es []error) string { | |
107c1cdb ND |
15 | if len(es) == 1 { |
16 | return fmt.Sprintf("1 error occurred:\n\t* %s\n\n", es[0]) | |
17 | } | |
18 | ||
bae9f6d2 JC |
19 | points := make([]string, len(es)) |
20 | for i, err := range es { | |
21 | points[i] = fmt.Sprintf("* %s", err) | |
22 | } | |
23 | ||
24 | return fmt.Sprintf( | |
107c1cdb ND |
25 | "%d errors occurred:\n\t%s\n\n", |
26 | len(es), strings.Join(points, "\n\t")) | |
bae9f6d2 | 27 | } |