diff --git a/orm/db.go b/orm/db.go index 1e3c996e..f639a27b 100644 --- a/orm/db.go +++ b/orm/db.go @@ -58,7 +58,7 @@ func (d *dbBase) collectValues(mi *modelInfo, ind reflect.Value, cols []string, if fi, _ = mi.fields.GetByAny(column); fi != nil { column = fi.column } else { - panic(fmt.Sprintf("wrong db field/column name `%s` for model `%s`", column, mi.fullName)) + panic(fmt.Errorf("wrong db field/column name `%s` for model `%s`", column, mi.fullName)) } if fi.dbcol == false || fi.auto && skipAuto { continue @@ -360,7 +360,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con values := make([]interface{}, 0, len(params)) for col, val := range params { if fi, ok := mi.fields.GetByAny(col); ok == false || fi.dbcol == false { - panic(fmt.Sprintf("wrong field/column name `%s`", col)) + panic(fmt.Errorf("wrong field/column name `%s`", col)) } else { columns = append(columns, fi.column) values = append(values, val) @@ -368,7 +368,7 @@ func (d *dbBase) UpdateBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con } if len(columns) == 0 { - panic("update params cannot empty") + panic(fmt.Errorf("update params cannot empty")) } tables := newDbTables(mi, d.ins) @@ -438,7 +438,7 @@ func (d *dbBase) DeleteBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Con } if cond == nil || cond.IsEmpty() { - panic("delete operation cannot execute without condition") + panic(fmt.Errorf("delete operation cannot execute without condition")) } Q := d.ins.TableQuote() @@ -533,9 +533,9 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi if errTyp { if one { - panic(fmt.Sprintf("wrong object type `%s` for rows scan, need *%s", val.Type(), mi.fullName)) + panic(fmt.Errorf("wrong object type `%s` for rows scan, need *%s", val.Type(), mi.fullName)) } else { - panic(fmt.Sprintf("wrong object type `%s` for rows scan, need *[]*%s or *[]%s", val.Type(), mi.fullName, mi.fullName)) + panic(fmt.Errorf("wrong object type `%s` for rows scan, need *[]*%s or *[]%s", val.Type(), mi.fullName, mi.fullName)) } } @@ -559,7 +559,7 @@ func (d *dbBase) ReadBatch(q dbQuerier, qs *querySet, mi *modelInfo, cond *Condi maps[fi.column] = true } } else { - panic(fmt.Sprintf("wrong field/column name `%s`", col)) + panic(fmt.Errorf("wrong field/column name `%s`", col)) } } if hasRel { @@ -717,7 +717,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri params := getFlatParams(fi, args, tz) if len(params) == 0 { - panic(fmt.Sprintf("operator `%s` need at least one args", operator)) + panic(fmt.Errorf("operator `%s` need at least one args", operator)) } arg := params[0] @@ -729,7 +729,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri sql = fmt.Sprintf("IN (%s)", strings.Join(marks, ", ")) } else { if len(params) > 1 { - panic(fmt.Sprintf("operator `%s` need 1 args not %d", operator, len(params))) + panic(fmt.Errorf("operator `%s` need 1 args not %d", operator, len(params))) } sql = d.ins.OperatorSql(operator) switch operator { @@ -758,7 +758,7 @@ func (d *dbBase) GenerateOperatorSql(mi *modelInfo, fi *fieldInfo, operator stri } params = nil } else { - panic(fmt.Sprintf("operator `%s` need a bool value not `%T`", operator, arg)) + panic(fmt.Errorf("operator `%s` need a bool value not `%T`", operator, arg)) } } } @@ -779,13 +779,13 @@ func (d *dbBase) setColsValues(mi *modelInfo, ind *reflect.Value, cols []string, value, err := d.convertValueFromDB(fi, val, tz) if err != nil { - panic(fmt.Sprintf("Raw value: `%v` %s", val, err.Error())) + panic(fmt.Errorf("Raw value: `%v` %s", val, err.Error())) } _, err = d.setFieldValue(fi, value, field) if err != nil { - panic(fmt.Sprintf("Raw value: `%v` %s", val, err.Error())) + panic(fmt.Errorf("Raw value: `%v` %s", val, err.Error())) } } } @@ -1034,7 +1034,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond case *ParamsList: typ = 3 default: - panic(fmt.Sprintf("unsupport read values type `%T`", container)) + panic(fmt.Errorf("unsupport read values type `%T`", container)) } tables := newDbTables(mi, d.ins) @@ -1117,7 +1117,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond value, err := d.convertValueFromDB(fi, val, tz) if err != nil { - panic(fmt.Sprintf("db value convert failed `%v` %s", val, err.Error())) + panic(fmt.Errorf("db value convert failed `%v` %s", val, err.Error())) } params[columns[i]] = value @@ -1132,7 +1132,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond value, err := d.convertValueFromDB(fi, val, tz) if err != nil { - panic(fmt.Sprintf("db value convert failed `%v` %s", val, err.Error())) + panic(fmt.Errorf("db value convert failed `%v` %s", val, err.Error())) } params = append(params, value) @@ -1146,7 +1146,7 @@ func (d *dbBase) ReadValues(q dbQuerier, qs *querySet, mi *modelInfo, cond *Cond value, err := d.convertValueFromDB(fi, val, tz) if err != nil { - panic(fmt.Sprintf("db value convert failed `%v` %s", val, err.Error())) + panic(fmt.Errorf("db value convert failed `%v` %s", val, err.Error())) } list = append(list, value) diff --git a/orm/db_tables.go b/orm/db_tables.go index ddaabf6a..a49418c4 100644 --- a/orm/db_tables.go +++ b/orm/db_tables.go @@ -126,7 +126,7 @@ func (t *dbTables) parseRelated(rels []string, depth int) { jtl = jt } else { - panic(fmt.Sprintf("unknown model/table name `%s`", ex)) + panic(fmt.Errorf("unknown model/table name `%s`", ex)) } } } diff --git a/orm/models_boot.go b/orm/models_boot.go index 61180914..564d9b40 100644 --- a/orm/models_boot.go +++ b/orm/models_boot.go @@ -14,7 +14,7 @@ func registerModel(model interface{}, prefix string) { typ := ind.Type() if val.Kind() != reflect.Ptr { - panic(fmt.Sprintf(" cannot use non-ptr model struct `%s`", getFullName(typ))) + panic(fmt.Errorf(" cannot use non-ptr model struct `%s`", getFullName(typ))) } table := getTableName(val) @@ -177,7 +177,7 @@ func bootStrap() { } } if added == false { - panic(fmt.Sprintf("cannot generate auto reverse field info `%s` to `%s`", fi.fullName, ffi.fullName)) + panic(fmt.Errorf("cannot generate auto reverse field info `%s` to `%s`", fi.fullName, ffi.fullName)) } } } diff --git a/orm/orm.go b/orm/orm.go index 51cdc495..35a94be2 100644 --- a/orm/orm.go +++ b/orm/orm.go @@ -44,13 +44,13 @@ func (o *orm) getMiInd(md interface{}) (mi *modelInfo, ind reflect.Value) { ind = reflect.Indirect(val) typ := ind.Type() if val.Kind() != reflect.Ptr { - panic(fmt.Sprintf(" cannot use non-ptr model struct `%s`", getFullName(typ))) + panic(fmt.Errorf(" cannot use non-ptr model struct `%s`", getFullName(typ))) } name := getFullName(typ) if mi, ok := modelCache.getByFN(name); ok { return mi, ind } - panic(fmt.Sprintf(" table: `%s` not found, maybe not RegisterModel", name)) + panic(fmt.Errorf(" table: `%s` not found, maybe not RegisterModel", name)) } func (o *orm) Read(md interface{}, cols ...string) error { @@ -141,14 +141,14 @@ func (o *orm) QueryTable(ptrStructOrTableName interface{}) (qs QuerySeter) { } } if qs == nil { - panic(fmt.Sprintf(" table name: `%s` not exists", name)) + panic(fmt.Errorf(" table name: `%s` not exists", name)) } return } func (o *orm) Using(name string) error { if o.isTx { - panic(" transaction has been start, cannot change db") + panic(fmt.Errorf(" transaction has been start, cannot change db")) } if al, ok := dataBaseCache.get(name); ok { o.alias = al @@ -158,7 +158,7 @@ func (o *orm) Using(name string) error { o.db = al.DB } } else { - return errors.New(fmt.Sprintf(" unknown db alias name `%s`", name)) + return fmt.Errorf(" unknown db alias name `%s`", name) } return nil } diff --git a/orm/orm_conds.go b/orm/orm_conds.go index 4a340f4b..91d69986 100644 --- a/orm/orm_conds.go +++ b/orm/orm_conds.go @@ -1,6 +1,7 @@ package orm import ( + "fmt" "strings" ) @@ -28,7 +29,7 @@ func NewCondition() *Condition { func (c Condition) And(expr string, args ...interface{}) *Condition { if expr == "" || len(args) == 0 { - panic(" args cannot empty") + panic(fmt.Errorf(" args cannot empty")) } c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args}) return &c @@ -36,7 +37,7 @@ func (c Condition) And(expr string, args ...interface{}) *Condition { func (c Condition) AndNot(expr string, args ...interface{}) *Condition { if expr == "" || len(args) == 0 { - panic(" args cannot empty") + panic(fmt.Errorf(" args cannot empty")) } c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isNot: true}) return &c @@ -45,7 +46,7 @@ func (c Condition) AndNot(expr string, args ...interface{}) *Condition { func (c *Condition) AndCond(cond *Condition) *Condition { c = c.clone() if c == cond { - panic("cannot use self as sub cond") + panic(fmt.Errorf(" cannot use self as sub cond")) } if cond != nil { c.params = append(c.params, condValue{cond: cond, isCond: true}) @@ -55,7 +56,7 @@ func (c *Condition) AndCond(cond *Condition) *Condition { func (c Condition) Or(expr string, args ...interface{}) *Condition { if expr == "" || len(args) == 0 { - panic(" args cannot empty") + panic(fmt.Errorf(" args cannot empty")) } c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isOr: true}) return &c @@ -63,7 +64,7 @@ func (c Condition) Or(expr string, args ...interface{}) *Condition { func (c Condition) OrNot(expr string, args ...interface{}) *Condition { if expr == "" || len(args) == 0 { - panic(" args cannot empty") + panic(fmt.Errorf(" args cannot empty")) } c.params = append(c.params, condValue{exprs: strings.Split(expr, ExprSep), args: args, isNot: true, isOr: true}) return &c @@ -72,7 +73,7 @@ func (c Condition) OrNot(expr string, args ...interface{}) *Condition { func (c *Condition) OrCond(cond *Condition) *Condition { c = c.clone() if c == cond { - panic("cannot use self as sub cond") + panic(fmt.Errorf(" cannot use self as sub cond")) } if cond != nil { c.params = append(c.params, condValue{cond: cond, isCond: true, isOr: true}) diff --git a/orm/orm_object.go b/orm/orm_object.go index c189e615..3c6d1f0e 100644 --- a/orm/orm_object.go +++ b/orm/orm_object.go @@ -23,10 +23,10 @@ func (o *insertSet) Insert(md interface{}) (int64, error) { typ := ind.Type() name := getFullName(typ) if val.Kind() != reflect.Ptr { - panic(fmt.Sprintf(" cannot use non-ptr model struct `%s`", name)) + panic(fmt.Errorf(" cannot use non-ptr model struct `%s`", name)) } if name != o.mi.fullName { - panic(fmt.Sprintf(" need model `%s` but found `%s`", o.mi.fullName, name)) + panic(fmt.Errorf(" need model `%s` but found `%s`", o.mi.fullName, name)) } id, err := o.orm.alias.DbBaser.InsertStmt(o.stmt, o.mi, ind, o.orm.alias.TZ) if err != nil { diff --git a/orm/orm_queryset.go b/orm/orm_queryset.go index 449587ca..41c63d8c 100644 --- a/orm/orm_queryset.go +++ b/orm/orm_queryset.go @@ -67,7 +67,7 @@ func (o querySet) RelatedSel(params ...interface{}) QuerySeter { case int: o.relDepth = val default: - panic(fmt.Sprintf(" wrong param kind: %v", val)) + panic(fmt.Errorf(" wrong param kind: %v", val)) } } } diff --git a/orm/orm_raw.go b/orm/orm_raw.go index c7dae5b4..864515ac 100644 --- a/orm/orm_raw.go +++ b/orm/orm_raw.go @@ -314,7 +314,7 @@ func (o *rawSet) loopSetRefs(refs []interface{}, sIdxes [][]int, sInds []reflect func (o *rawSet) QueryRow(containers ...interface{}) error { if len(containers) == 0 { - panic(" need at least one arg") + panic(fmt.Errorf(" need at least one arg")) } refs := make([]interface{}, 0, len(containers)) @@ -327,7 +327,7 @@ func (o *rawSet) QueryRow(containers ...interface{}) error { ind := reflect.Indirect(val) if val.Kind() != reflect.Ptr { - panic(" all args must be use ptr") + panic(fmt.Errorf(" all args must be use ptr")) } etyp := ind.Type() @@ -377,7 +377,7 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) { val := reflect.ValueOf(container) sInd := reflect.Indirect(val) if val.Kind() != reflect.Ptr || sInd.Kind() != reflect.Slice { - panic(" all args must be use ptr slice") + panic(fmt.Errorf(" all args must be use ptr slice")) } etyp := sInd.Type().Elem() @@ -440,7 +440,7 @@ func (o *rawSet) readValues(container interface{}) (int64, error) { case *ParamsList: typ = 3 default: - panic(fmt.Sprintf(" unsupport read values type `%T`", container)) + panic(fmt.Errorf(" unsupport read values type `%T`", container)) } query := o.query