Skip to content

Commit

Permalink
zapcore: Slim down changes to unit test improvements only
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhwang committed Mar 4, 2024
1 parent 6a4971d commit c3d3011
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 38 deletions.
23 changes: 3 additions & 20 deletions zapcore/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ import (
"go.uber.org/zap/internal/pool"
)

// Encodes the given error into fields of an object.
//
// If the error implements ObjectMarshaler, this takes precedence and a field
// with the given name is added with the corresponding MarshalLogObject.
//
// Otherwise, a field with the given name is added for the error message.
// Encodes the given error into fields of an object. A field with the given
// name is added for the error message.
//
// If the error implements fmt.Formatter, a field with the name ${key}Verbose
// is also added with the full verbose error message.
Expand All @@ -41,16 +37,6 @@ import (
// causer (from github.com/pkg/errors), a ${key}Causes field is added with an
// array of objects containing the errors this error was comprised of.
//
// In the case of a ObjectMarshaler,
//
// {
// "error": {
// ...
// }
// }
//
// Otherwise,
//
// {
// "error": err.Error(),
// "errorVerbose": fmt.Sprintf("%+v", err),
Expand All @@ -74,9 +60,6 @@ func encodeError(key string, err error, enc ObjectEncoder) (retErr error) {
retErr = fmt.Errorf("PANIC=%v", rerr)
}
}()
if obj, ok := err.(ObjectMarshaler); ok {
return enc.AddObject(key, obj)
}

basic := err.Error()
enc.AddString(key, basic)
Expand All @@ -96,7 +79,7 @@ func encodeError(key string, err error, enc ObjectEncoder) (retErr error) {
}

type errorGroup interface {
// Errors provides read-only access to the underlying list of errors, preferably
// Provides read-only access to the underlying list of errors, preferably
// without causing any allocs.
Errors() []error
}
Expand Down
18 changes: 0 additions & 18 deletions zapcore/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,12 @@ func (e customMultierr) Errors() []error {
}
}

type customObjMarshalerErr struct{}

func (e customObjMarshalerErr) Error() string { return "object marshaler string" }

func (e customObjMarshalerErr) MarshalLogObject(enc ObjectEncoder) error {
enc.AddString("nested", "object marshaler nested")
return nil
}

func TestErrorEncoding(t *testing.T) {
tests := []struct {
key string
iface any
want map[string]any
}{
{
key: "k",
iface: customObjMarshalerErr{},
want: map[string]any{
"k": map[string]any{
"nested": "object marshaler nested",
},
},
},
{
key: "k",
iface: errTooManyUsers(2),
Expand Down

0 comments on commit c3d3011

Please sign in to comment.