Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav authored Nov 24, 2020
1 parent de2b032 commit fbb85ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions zapcore/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<nil>". 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, "<nil>" is a nice result.
if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() {
enc.AddString(key, "<nil>")
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions zapcore/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<nil>". The likeliest causes are a
// Stringer that fails to guard against nil or a nil pointer for a
// value receiver, and in either case, "<nil>" is a nice result.
Expand All @@ -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)
}
}()

Expand Down

0 comments on commit fbb85ad

Please sign in to comment.