mirror of https://github.com/go-gorm/gorm.git
Don't add duplicated error
This commit is contained in:
parent
24aeec7a1e
commit
81c00fdc8f
11
errors.go
11
errors.go
|
@ -26,8 +26,19 @@ func (errs Errors) GetErrors() []error {
|
|||
}
|
||||
|
||||
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{}
|
||||
|
|
8
main.go
8
main.go
|
@ -518,10 +518,10 @@ func (s *DB) AddError(err error) error {
|
|||
s.log(err)
|
||||
}
|
||||
|
||||
if e, ok := err.(errorsInterface); ok {
|
||||
err = Errors{errors: append(s.GetErrors(), e.GetErrors()...)}
|
||||
} else {
|
||||
err = Errors{errors: append(s.GetErrors(), err)}
|
||||
errors := Errors{errors: s.GetErrors()}
|
||||
errors.Add(err)
|
||||
if len(errors.GetErrors()) > 1 {
|
||||
err = errors
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue