diff --git a/association.go b/association.go index 3a2942fd..572f1526 100644 --- a/association.go +++ b/association.go @@ -1,7 +1,6 @@ package gorm import ( - "errors" "fmt" "reflect" "strings" @@ -441,7 +440,7 @@ func (association *Association) saveAssociation(clear bool, values ...interface{ break } - association.Error = errors.New("invalid association values, length doesn't match") + association.Error = ErrInvalidValueOfLength return } diff --git a/callbacks.go b/callbacks.go index d1b8cd58..5b878af0 100644 --- a/callbacks.go +++ b/callbacks.go @@ -104,7 +104,7 @@ func (p *processor) Execute(db *DB) { stmt.ReflectValue = stmt.ReflectValue.Elem() } if !stmt.ReflectValue.IsValid() { - db.AddError(fmt.Errorf("invalid value")) + db.AddError(ErrInvalidValue) } } diff --git a/errors.go b/errors.go index 08755083..5f464d2b 100644 --- a/errors.go +++ b/errors.go @@ -31,4 +31,10 @@ var ( ErrEmptySlice = errors.New("empty slice found") // ErrDryRunModeUnsupported dry run mode unsupported ErrDryRunModeUnsupported = errors.New("dry run mode unsupported") + // ErrInvaildDB invalid db + ErrInvaildDB = errors.New("invalid db") + // ErrInvalidValue invalid value + ErrInvalidValue = errors.New("invalid value") + // ErrInvalidValueOfLength invalid values do not match length + ErrInvalidValueOfLength = errors.New("invalid association values, length doesn't match") ) diff --git a/gorm.go b/gorm.go index f11fb9e1..0eb377e9 100644 --- a/gorm.go +++ b/gorm.go @@ -3,7 +3,6 @@ package gorm import ( "context" "database/sql" - "errors" "fmt" "sync" "time" @@ -331,7 +330,7 @@ func (db *DB) DB() (*sql.DB, error) { return sqldb, nil } - return nil, errors.New("invalid db") + return nil, ErrInvaildDB } func (db *DB) getInstance() *DB {