Don't add duplicated error

This commit is contained in:
Jinzhu 2015-08-18 11:06:10 +08:00
parent 24aeec7a1e
commit 81c00fdc8f
2 changed files with 16 additions and 5 deletions

View File

@ -26,7 +26,18 @@ func (errs Errors) GetErrors() []error {
}
func (errs *Errors) Add(err error) {
errs.errors = append(errs.errors, err)
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 {

View File

@ -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
}
}