forked from go-gorm/gorm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
49 lines (42 loc) · 945 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
45
46
47
48
49
package gorm
import (
"errors"
"strings"
)
var (
RecordNotFound = errors.New("record not found")
InvalidSql = errors.New("invalid sql")
NoNewAttrs = errors.New("no new attributes")
NoValidTransaction = errors.New("no valid transaction")
CantStartTransaction = errors.New("can't start transaction")
)
type errorsInterface interface {
GetErrors() []error
}
type Errors struct {
errors []error
}
func (errs Errors) GetErrors() []error {
return errs.errors
}
func (errs *Errors) Add(err error) {
if errors, ok := err.(errorsInterface); ok {
for _, err := range errors.GetErrors() {
errs.Add(err)
}
} else {
for _, e := range errs.errors {
if err == e {
return
}
}
errs.errors = append(errs.errors, err)
}
}
func (errs Errors) Error() string {
var errors = []string{}
for _, e := range errs.errors {
errors = append(errors, e.Error())
}
return strings.Join(errors, "; ")
}