From a5cead456ae8230b3419ed9ec83ff0bf6b98189e Mon Sep 17 00:00:00 2001 From: FMLS Date: Thu, 24 Sep 2020 17:32:47 +0800 Subject: [PATCH] BUGFIX: judge nil pointer stored in error interface --- error.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/error.go b/error.go index 65982a51e..c74b30487 100644 --- a/error.go +++ b/error.go @@ -21,9 +21,9 @@ package zap import ( - "sync" - "go.uber.org/zap/zapcore" + "reflect" + "sync" ) var _errArrayElemPool = sync.Pool{New: func() interface{} { @@ -43,7 +43,7 @@ func Error(err error) Field { // For the common case in which the key is simply "error", the Error function // is shorter and less repetitive. func NamedError(key string, err error) Field { - if err == nil { + if err == nil || reflect.ValueOf(err).IsNil() { return Skip() } return Field{Key: key, Type: zapcore.ErrorType, Interface: err}