From 081dece1a3f2a4761f25cc27ebbb36d7a0fa950e Mon Sep 17 00:00:00 2001 From: henng Date: Sat, 12 Oct 2019 15:50:21 +0800 Subject: [PATCH] fixed 'bad access: nil dereference' when calling Error() method if itself is a nil reference. --- terror/terror.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/terror/terror.go b/terror/terror.go index 91350dd72..b67304102 100644 --- a/terror/terror.go +++ b/terror/terror.go @@ -18,6 +18,7 @@ import ( "fmt" "strconv" + "github.com/modern-go/reflect2" "github.com/pingcap/errors" "github.com/pingcap/parser/mysql" log "github.com/sirupsen/logrus" @@ -213,10 +214,16 @@ func (e *Error) Location() (file string, line int) { // Error implements error interface. func (e *Error) Error() string { + if reflect2.IsNil(e) { + return "" + } return fmt.Sprintf("[%s:%d]%s", e.class, e.code, e.getMsg()) } func (e *Error) getMsg() string { + if reflect2.IsNil(e) { + return "" + } if len(e.args) > 0 { return fmt.Sprintf(e.message, e.args...) }