diff --git a/error_test.go b/error_test.go index 674b1596a..64dab191c 100644 --- a/error_test.go +++ b/error_test.go @@ -22,11 +22,11 @@ package zap import ( "errors" + "fmt" "testing" "go.uber.org/zap/zapcore" - richErrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -79,7 +79,7 @@ func TestErrorArrayConstructor(t *testing.T) { } func TestErrorsArraysHandleRichErrors(t *testing.T) { - errs := []error{richErrors.New("egad")} + errs := []error{fmt.Errorf("egad")} enc := zapcore.NewMapObjectEncoder() Errors("k", errs).AddTo(enc) @@ -94,6 +94,4 @@ func TestErrorsArraysHandleRichErrors(t *testing.T) { errMap, ok := serialized.(map[string]interface{}) require.True(t, ok, "Expected serialized error to be a map, got %T.", serialized) assert.Equal(t, "egad", errMap["error"], "Unexpected standard error string.") - assert.Contains(t, errMap["errorVerbose"], "egad", "Verbose error string should be a superset of standard error.") - assert.Contains(t, errMap["errorVerbose"], "TestErrorsArraysHandleRichErrors", "Verbose error string should contain a stacktrace.") } diff --git a/go.mod b/go.mod index bf4a1b363..455dae496 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.19 require ( github.com/benbjohnson/clock v1.3.0 - github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.1 go.uber.org/goleak v1.2.0 go.uber.org/multierr v1.10.0 diff --git a/go.sum b/go.sum index 77712781d..ffa795531 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/zapcore/error_test.go b/zapcore/error_test.go index 900f52020..d8263abc1 100644 --- a/zapcore/error_test.go +++ b/zapcore/error_test.go @@ -26,7 +26,6 @@ import ( "io" "testing" - richErrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" "go.uber.org/multierr" @@ -113,34 +112,28 @@ func TestErrorEncoding(t *testing.T) { }, { k: "k", - iface: richErrors.WithMessage(errors.New("egad"), "failed"), + iface: fmt.Errorf("failed: %w", errors.New("egad")), want: map[string]interface{}{ - "k": "failed: egad", - "kVerbose": "egad\nfailed", + "k": "failed: egad", }, }, { k: "error", iface: multierr.Combine( - richErrors.WithMessage( + fmt.Errorf("hello: %w", multierr.Combine(errors.New("foo"), errors.New("bar")), - "hello", ), errors.New("baz"), - richErrors.WithMessage(errors.New("qux"), "world"), + fmt.Errorf("world: %w", errors.New("qux")), ), want: map[string]interface{}{ "error": "hello: foo; bar; baz; world: qux", "errorCauses": []interface{}{ map[string]interface{}{ "error": "hello: foo; bar", - "errorVerbose": "the following errors occurred:\n" + - " - foo\n" + - " - bar\n" + - "hello", }, map[string]interface{}{"error": "baz"}, - map[string]interface{}{"error": "world: qux", "errorVerbose": "qux\nworld"}, + map[string]interface{}{"error": "world: qux"}, }, }, }, @@ -161,17 +154,10 @@ func TestErrorEncoding(t *testing.T) { func TestRichErrorSupport(t *testing.T) { f := Field{ Type: ErrorType, - Interface: richErrors.WithMessage(richErrors.New("egad"), "failed"), + Interface: fmt.Errorf("failed: %w", errors.New("egad")), Key: "k", } enc := NewMapObjectEncoder() f.AddTo(enc) assert.Equal(t, "failed: egad", enc.Fields["k"], "Unexpected basic error message.") - - serialized := enc.Fields["kVerbose"] - // Don't assert the exact format used by a third-party package, but ensure - // that some critical elements are present. - assert.Regexp(t, `egad`, serialized, "Expected original error message to be present.") - assert.Regexp(t, `failed`, serialized, "Expected error annotation to be present.") - assert.Regexp(t, `TestRichErrorSupport`, serialized, "Expected calling function to be present in stacktrace.") }