-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
43 lines (34 loc) · 739 Bytes
/
errors.go
File metadata and controls
43 lines (34 loc) · 739 Bytes
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
41
42
43
package odize
import "errors"
var (
ErrTestAlreadyExists = errors.New("test already exists")
)
// Error - return error string
func (e *ListError) Error() string {
result := ""
for _, item := range e.errors {
result += item.Error() + ", "
}
return result
}
// Unwrap - returns list of errors
func (e *ListError) Unwrap() []error {
return e.errors
}
// Append - append error to list
func (e *ListError) Append(err error) {
e.errors = append(e.errors, err)
}
func (e *ListError) Len() int {
return len(e.errors)
}
// Pop - remove the first error from the list and return
func (e *ListError) Pop() error {
if len(e.errors) == 0 {
return nil
}
first := e.errors[0]
rest := e.errors[1:]
e.errors = rest
return first
}