-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors.go
44 lines (35 loc) · 942 Bytes
/
errors.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
37
38
39
40
41
42
43
44
package redis
import (
"strings"
"libs.altipla.consulting/errors"
)
var (
// ErrNoSuchEntity is returned from a Get operation when there is not a model
// that matches the query
ErrNoSuchEntity = errors.New("no such entity")
ErrDone = errors.New("done")
)
// MultiError is returned from batch operations with the error of each operation.
// If a batch operation does not fails this will be nil too.
type MultiError []error
// Error returns the composed error message with all the individual ones.
func (merr MultiError) Error() string {
var msg []string
for _, err := range merr {
if err == nil {
msg = append(msg, "<nil>")
} else {
msg = append(msg, err.Error())
}
}
return strings.Join(msg, "; ")
}
// HasError checks if there is really an error on the list or all of them are empty.
func (merr MultiError) HasError() bool {
for _, err := range merr {
if err != nil {
return true
}
}
return false
}