-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
43 lines (35 loc) · 816 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
package badgerquery
import (
"errors"
"strings"
)
var (
ErrDBClosed = errors.New("db already closed")
ErrTableExists = errors.New("table already exists")
ErrTableNotExists = errors.New("table not exists")
ErrIndexNotExists = errors.New("index not exists")
ErrItemExists = errors.New("item already exists")
)
type MultiError struct {
errors []error
}
func NewMultiError() *MultiError {
return &MultiError{
errors: []error{},
}
}
func (this *MultiError) HasErrors() bool {
return len(this.errors) > 0
}
func (this *MultiError) Add(err error) {
if err != nil {
this.errors = append(this.errors, err)
}
}
func (this *MultiError) Error() string {
errMsgs := []string{}
for _, err := range this.errors {
errMsgs = append(errMsgs, err.Error())
}
return strings.Join(errMsgs, "\n")
}