feat: support go1.13 errors.Is
This commit is contained in:
parent
5b3e40ac12
commit
937ae81751
7
error_12.go
Normal file
7
error_12.go
Normal file
@ -0,0 +1,7 @@
|
||||
// +build !go1.13
|
||||
|
||||
package gorm
|
||||
|
||||
func isError(err, target error) bool {
|
||||
return err == target
|
||||
}
|
7
error_13.go
Normal file
7
error_13.go
Normal file
@ -0,0 +1,7 @@
|
||||
// +build go1.13
|
||||
|
||||
package gorm
|
||||
|
||||
import "errors"
|
||||
|
||||
var isError = errors.Is
|
@ -25,12 +25,12 @@ type Errors []error
|
||||
func IsRecordNotFoundError(err error) bool {
|
||||
if errs, ok := err.(Errors); ok {
|
||||
for _, err := range errs {
|
||||
if err == ErrRecordNotFound {
|
||||
if isError(err, ErrRecordNotFound) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return err == ErrRecordNotFound
|
||||
return isError(err, ErrRecordNotFound)
|
||||
}
|
||||
|
||||
// GetErrors gets all errors that have occurred and returns a slice of errors (Error type)
|
||||
|
4
main.go
4
main.go
@ -592,7 +592,7 @@ func (s *DB) NewRecord(value interface{}) bool {
|
||||
// RecordNotFound check if returning ErrRecordNotFound error
|
||||
func (s *DB) RecordNotFound() bool {
|
||||
for _, err := range s.GetErrors() {
|
||||
if err == ErrRecordNotFound {
|
||||
if isError(err, ErrRecordNotFound) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -776,7 +776,7 @@ func (s *DB) SetJoinTableHandler(source interface{}, column string, handler Join
|
||||
// AddError add error to the db
|
||||
func (s *DB) AddError(err error) error {
|
||||
if err != nil {
|
||||
if err != ErrRecordNotFound {
|
||||
if !isError(err, ErrRecordNotFound) {
|
||||
if s.logMode == defaultLogMode {
|
||||
go s.print("error", fileWithLineNum(), err)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user