You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'bad access: nil dereference' when calling Error()/getMsg() method of type Error in terror/terror.go #576
We can see above, when calling fmt.Sprintf() with job.Error is a nil dereference, it will reach /your_go_root/src/fmt/print.go::printArg(), in this case arg == nil is not true.
Finally, we got /your_go_rootc/src/fmt/print.go::handleMethods(), in this case v or p.arg is a nil dereference cause it's from job.Error, and it is an error type casue job.Error is a pointer of terror.Error, so error occurs when calling v.Error().
switch verb {
case 'v', 's', 'x', 'X', 'q':
switch v := p.arg.(type) {
case error:
handled = true
defer p.catchPanic(p.arg, verb, "Error")
p.fmtString(v.Error(), verb)
return
......
}
......
}
Here's a simple test case that you can re-produce the error in debug mode:
type ABC struct {
a int64
b bool
c *terror.Error
}
func TestSprintf(t *testing.T) {
abc := &ABC{c: nil}
s := fmt.Sprintf("Testing's Err: %v", abc.c)
println(s)
}
Activity
henng commentedon Oct 12, 2019
Made a try to fix this, see #577
bb7133 commentedon Oct 29, 2020
Just a ping, @henng may you update #577 please?