380 Star 2.5K Fork 618

GVPJohn / gf

 / 详情

gf的gdb模块发生错误,结果转换发生panic错误

已完成
创建于  
2018-11-09 11:27

错误详情

/home/wwg/software/golang/go/src/runtime/panic.go:513 +0x1b9
gitee.com/johng/gf/g/container/gvar.(*Var).Val(...)
        /home/wwg/software/golang/gopath/pkg/mod/gitee.com/johng/gf@v1.0.898/g/container/gvar/gvar.go:42
gitee.com/johng/gf/g/container/gvar.(*Var).String(0x0, 0x0, 0x0)
        /home/wwg/software/golang/gopath/pkg/mod/gitee.com/johng/gf@v1.0.898/g/container/gvar/gvar.go:55 +0x2e
vector/smartstore/src/core/pt/network/socket/model.GetBoxEventInfo(0xc00035cce8, 0x8, 0x1, 0x11, 0x0, 0x0, 0x0, 0x0)
        /home/wwg/mydata/data/go/smartstore/src/core/pt/network/socket/model/model.go:213 +0x4c9
vector/smartstore/src/core/pt/network/packethandle.infoCommand(0xc00035cce8, 0x8, 0xc00036c592, 0x3, 0xe, 0x8, 0xc0000a8060, 0xc000684000)

发生错误的代码

if r, err := db.Table("`event` ev").
		InnerJoin("police po", "ev.used = po.po_id").
		InnerJoin("certificate ce", "po.ce_id = ce.ce_id").
		InnerJoin("certposition cp", "cp.ce_id = ce.ce_id").
		InnerJoin("control ct", "cp.co_id = ct.co_id").
		InnerJoin("store st", "st.co_id = ct.co_id AND cp.se_id = st.se_id").
		InnerJoin("box bo", "bo.se_id = st.se_id AND cp.bo_id = bo.bo_id").
		Fields("ev.e_id AS eid").
		Where("ct.hardwarecode=?", hardware).
		And("st.number=?", stnumber).
		And("bo.boxnumber=?", boxnumber).
		And("ev.status <> ?", "remand").
		Value(); err == nil {
		return r.String(), nil
	} else {
		return "", fmt.Errorf("执行出错")
	}

错误发生在r.String()那一行代码

评论 (3)

Ryan Newman 创建了任务
Ryan Newman 修改了标题
Ryan Newman 修改了描述
Ryan Newman 修改了标题
Ryan Newman 修改了描述
展开全部操作日志

找到原因了,就是r的结果可能会为nil,当为nil时就会发生此错误

@Ryan Newman 是的,gform在当查询的结果为空的时候返回的结果和error值都为nil(有的orm库会在查询结果为空时返回一个error,不过从严谨性上考虑,gform并没有这么做),常见的返回结果判断为以下方式:

if r, err := 链式操作; err == nil && r != nil {

} else {

}
John 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1309327 johng 1705475649
Go
1
https://gitee.com/johng/gf.git
git@gitee.com:johng/gf.git
johng
gf
gf

搜索帮助