// logutil.BgLogger().Info("[ddl] start DDL job", zap.String("job", job.String()), zap.String("query", job.Query))
func (job *Job) String() string {
rowCount := job.GetRowCount()
return fmt.Sprintf("ID:%d, Type:%s, State:%s, SchemaState:%s, SchemaID:%d, TableID:%d, RowCount:%d, ArgLen:%d, start time: %v, Err:%v, ErrCount:%d, SnapshotVersion:%v",
job.ID, job.Type, job.State, job.SchemaState, job.SchemaID, job.TableID, rowCount, len(job.Args), TSConvert2Time(job.StartTS), job.Error, job.ErrorCount, job.SnapshotVer)
}
func (p *pp) printArg(arg interface{}, verb rune) {
p.arg = arg
p.value = reflect.Value{}
if arg == nil {
switch verb {
case 'T', 'v':
p.fmt.padString(nilAngleString)
default:
p.badVerb(verb)
}
return
}
......
}
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
......
}
......
}
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)
}
Bug Report
Debugging a test case in TiDB and stuck in debug mode, see error of 'bad access: nil dereference'Here's an exactly case:
job.Error is a nil dereference, it will reach /your_go_root/src/fmt/print.go::printArg(), in this casearg == nilis not true.v or p.argis 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().Here's a simple test case that you can re-produce the error in debug mode:
No Errorsbad access: nil dereference[email protected]