invalid db error and value and invalid value length error (#4151)

This commit is contained in:
heige 2021-03-07 10:56:32 +08:00 committed by GitHub
parent a948c84607
commit 495ec4bd87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 5 deletions

View File

@ -1,7 +1,6 @@
package gorm package gorm
import ( import (
"errors"
"fmt" "fmt"
"reflect" "reflect"
"strings" "strings"
@ -441,7 +440,7 @@ func (association *Association) saveAssociation(clear bool, values ...interface{
break break
} }
association.Error = errors.New("invalid association values, length doesn't match") association.Error = ErrInvalidValueOfLength
return return
} }

View File

@ -104,7 +104,7 @@ func (p *processor) Execute(db *DB) {
stmt.ReflectValue = stmt.ReflectValue.Elem() stmt.ReflectValue = stmt.ReflectValue.Elem()
} }
if !stmt.ReflectValue.IsValid() { if !stmt.ReflectValue.IsValid() {
db.AddError(fmt.Errorf("invalid value")) db.AddError(ErrInvalidValue)
} }
} }

View File

@ -31,4 +31,10 @@ var (
ErrEmptySlice = errors.New("empty slice found") ErrEmptySlice = errors.New("empty slice found")
// ErrDryRunModeUnsupported dry run mode unsupported // ErrDryRunModeUnsupported dry run mode unsupported
ErrDryRunModeUnsupported = errors.New("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")
) )

View File

@ -3,7 +3,6 @@ package gorm
import ( import (
"context" "context"
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"sync" "sync"
"time" "time"
@ -331,7 +330,7 @@ func (db *DB) DB() (*sql.DB, error) {
return sqldb, nil return sqldb, nil
} }
return nil, errors.New("invalid db") return nil, ErrInvaildDB
} }
func (db *DB) getInstance() *DB { func (db *DB) getInstance() *DB {