From dd0d4d931f0d6b52e3c8df75496b0a1aaa5667e6 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 14 Aug 2015 14:53:26 +0800 Subject: [PATCH] Add errorsInterface --- errors.go | 4 ++++ main.go | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/errors.go b/errors.go index f4743b0a..23fedd7f 100644 --- a/errors.go +++ b/errors.go @@ -13,6 +13,10 @@ var ( CantStartTransaction = errors.New("can't start transaction") ) +type errorsInterface interface { + GetErrors() []error +} + type Errors struct { errors []error } diff --git a/main.go b/main.go index 8457dc96..d1898142 100644 --- a/main.go +++ b/main.go @@ -518,7 +518,11 @@ 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 @@ -526,10 +530,11 @@ func (s *DB) AddError(err error) error { 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 }