From 70760b8b1021e6d558ba7446c89c4776df3c200c Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:57:55 +0800 Subject: [PATCH] add nil check --- executor/adapter.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/executor/adapter.go b/executor/adapter.go index afbee5c989a8e..ed2c0566e0f81 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -1611,8 +1611,10 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) { } func extractMsgFromSQLWarn(SQLWarn *stmtctx.SQLWarn) string { + // Currently, this function is only used in extractMsgFromSQLWarn(). + // extractMsgFromSQLWarn() can make sure SQLWarn is not nil so no need to add a nil check here. warn := errors.Cause(SQLWarn.Err) - if x, ok := warn.(*terror.Error); ok { + if x, ok := warn.(*terror.Error); ok && x != nil { sqlErr := terror.ToSQLError(x) return sqlErr.Message }