blob: b30adb0ac5b3f67e9db2c5b89ad4eb70f210ae05 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package errorhelper
// NewMultiError returns a new MultiError object.
func NewMultiError() *MultiError {
return &MultiError{
errors: []error{},
}
}
// MultiError is a structure for holding multiple errors so they
// can be checked at a later point.
type MultiError struct {
errors []error
}
// Add will add the given error if it is not nil.
func (m *MultiError) Add(err error) {
if err != nil {
m.errors = append(m.errors, err)
}
}
// HasErrors will return true if any non-nil errors have been
// added.
func (m *MultiError) HasErrors() bool {
if len(m.errors) > 0 {
return true
}
return false
}
// Error will print the first error is encountered.
func (m *MultiError) Error() string {
if !m.HasErrors() {
return ""
}
return m.errors[0].Error()
}
|