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
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
}

View File

@ -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)
}
}

View File

@ -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")
)

View File

@ -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 {