-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorList.go
36 lines (31 loc) · 858 Bytes
/
errorList.go
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
package Common
import (
"fmt"
"strings"
)
// errorList keeps a list of errors in a string array. From an instance of errorList, an error will be created if there
// is an entry in the array.
// This may be extended to keep more information re the error, such as the call stack. There is some good example on the web
type errorList struct {
list []string
}
// Error: Create an error, if there is an entry in the array
func (self *errorList) Error() error {
if len(self.list) > 0 {
return fmt.Errorf(strings.Join(self.list, "\n"))
}
return nil
}
// Add: Add an error to the list
func (self *errorList) Add(err error) {
if err != nil {
self.list = append(self.list, err.Error())
}
//return err
}
// An internal constructor used to create this error list
func newErrorList() *errorList {
return &errorList{
list: make([]string, 0, 16),
}
}