diff --git a/zapcore/error.go b/zapcore/error.go index a338f8532..f2a07d786 100644 --- a/zapcore/error.go +++ b/zapcore/error.go @@ -49,7 +49,7 @@ func encodeError(key string, err error, enc ObjectEncoder) (retErr error) { defer func() { if rerr := recover(); rerr != nil { // If it's a nil pointer, just say "". The likeliest causes are a - // Stringer that fails to guard against nil or a nil pointer for a + // error that fails to guard against nil or a nil pointer for a // value receiver, and in either case, "" is a nice result. if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { enc.AddString(key, "") @@ -65,7 +65,7 @@ func encodeError(key string, err error, enc ObjectEncoder) (retErr error) { switch e := err.(type) { case errorGroup: - retErr = enc.AddArray(key+"Causes", errArray(e.Errors())) + return enc.AddArray(key+"Causes", errArray(e.Errors())) case fmt.Formatter: verbose := fmt.Sprintf("%+v", e) if verbose != basic { @@ -74,7 +74,7 @@ func encodeError(key string, err error, enc ObjectEncoder) (retErr error) { enc.AddString(key+"Verbose", verbose) } } - return retErr + return nil } type errorGroup interface { diff --git a/zapcore/field.go b/zapcore/field.go index b46449e49..e0105868e 100644 --- a/zapcore/field.go +++ b/zapcore/field.go @@ -209,7 +209,7 @@ func encodeStringer(key string, stringer interface{}, enc ObjectEncoder) (retErr // Try to capture panics (from nil references or otherwise) when calling // the String() method, similar to https://golang.org/src/fmt/print.go#L540 defer func() { - if rerr := recover(); rerr != nil { + if err := recover(); err != nil { // If it's a nil pointer, just say "". The likeliest causes are a // Stringer that fails to guard against nil or a nil pointer for a // value receiver, and in either case, "" is a nice result. @@ -218,7 +218,7 @@ func encodeStringer(key string, stringer interface{}, enc ObjectEncoder) (retErr return } - retErr = fmt.Errorf("PANIC=%v", rerr) + retErr = fmt.Errorf("PANIC=%v", err) } }()