2013-11-15 14:36:39 +04:00
|
|
|
package gorm
|
|
|
|
|
2015-08-13 11:42:13 +03:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
2013-11-15 14:36:39 +04:00
|
|
|
|
|
|
|
var (
|
2015-02-17 03:34:01 +03:00
|
|
|
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")
|
2013-11-15 14:36:39 +04:00
|
|
|
)
|
2015-08-13 11:42:13 +03:00
|
|
|
|
2015-08-14 09:53:26 +03:00
|
|
|
type errorsInterface interface {
|
|
|
|
GetErrors() []error
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:42:13 +03:00
|
|
|
type Errors struct {
|
|
|
|
errors []error
|
|
|
|
}
|
|
|
|
|
2015-08-14 07:29:53 +03:00
|
|
|
func (errs Errors) GetErrors() []error {
|
2015-08-13 11:42:13 +03:00
|
|
|
return errs.errors
|
|
|
|
}
|
|
|
|
|
|
|
|
func (errs *Errors) Add(err error) {
|
2015-08-18 06:06:10 +03:00
|
|
|
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)
|
|
|
|
}
|
2015-08-13 11:42:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (errs Errors) Error() string {
|
|
|
|
var errors = []string{}
|
|
|
|
for _, e := range errs.errors {
|
|
|
|
errors = append(errors, e.Error())
|
|
|
|
}
|
|
|
|
return strings.Join(errors, "; ")
|
|
|
|
}
|