Skip to content

Commit

Permalink
Don't add duplicated error
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Aug 18, 2015
1 parent 24aeec7 commit 81c00fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 81c00fd

Please sign in to comment.