Skip to content

Commit

Permalink
Add errorsInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Aug 14, 2015
1 parent 0996ddb commit dd0d4d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var (
CantStartTransaction = errors.New("can't start transaction")
)

type errorsInterface interface {
GetErrors() []error
}

type Errors struct {
errors []error
}
Expand Down
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,23 @@ func (s *DB) AddError(err error) error {
s.log(err)
}

err = Errors{errors: append(s.GetErrors(), err)}
if e, ok := err.(errorsInterface); ok {
err = Errors{errors: append(s.GetErrors(), e.GetErrors()...)}
} else {
err = Errors{errors: append(s.GetErrors(), err)}
}
}

s.Error = err
}
return err
}

func (s *DB) GetErrors() []error {
if errs, ok := s.Error.(Errors); ok {
return errs.errors
} else {
func (s *DB) GetErrors() (errors []error) {
if errs, ok := s.Error.(errorsInterface); ok {
return errs.GetErrors()
} else if s.Error != nil {
return []error{s.Error}
}
return
}

0 comments on commit dd0d4d9

Please sign in to comment.