Skip to content

Commit 05c4b6c

Browse files
authored
Remove dependency on github.com/pkg/errors (#1255)
1 parent d1a1923 commit 05c4b6c

File tree

4 files changed

+8
-27
lines changed

4 files changed

+8
-27
lines changed

error_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ package zap
2222

2323
import (
2424
"errors"
25+
"fmt"
2526
"testing"
2627

2728
"go.uber.org/zap/zapcore"
2829

29-
richErrors "github.com/pkg/errors"
3030
"github.com/stretchr/testify/assert"
3131
"github.com/stretchr/testify/require"
3232
)
@@ -79,7 +79,7 @@ func TestErrorArrayConstructor(t *testing.T) {
7979
}
8080

8181
func TestErrorsArraysHandleRichErrors(t *testing.T) {
82-
errs := []error{richErrors.New("egad")}
82+
errs := []error{fmt.Errorf("egad")}
8383

8484
enc := zapcore.NewMapObjectEncoder()
8585
Errors("k", errs).AddTo(enc)
@@ -94,6 +94,4 @@ func TestErrorsArraysHandleRichErrors(t *testing.T) {
9494
errMap, ok := serialized.(map[string]interface{})
9595
require.True(t, ok, "Expected serialized error to be a map, got %T.", serialized)
9696
assert.Equal(t, "egad", errMap["error"], "Unexpected standard error string.")
97-
assert.Contains(t, errMap["errorVerbose"], "egad", "Verbose error string should be a superset of standard error.")
98-
assert.Contains(t, errMap["errorVerbose"], "TestErrorsArraysHandleRichErrors", "Verbose error string should contain a stacktrace.")
9997
}

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.19
44

55
require (
66
github.com/benbjohnson/clock v1.3.0
7-
github.com/pkg/errors v0.9.1
87
github.com/stretchr/testify v1.8.1
98
go.uber.org/goleak v1.2.0
109
go.uber.org/multierr v1.10.0

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
77
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
88
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
99
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
10-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
11-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1210
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1311
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1412
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

zapcore/error_test.go

+6-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"io"
2727
"testing"
2828

29-
richErrors "github.com/pkg/errors"
3029
"github.com/stretchr/testify/assert"
3130

3231
"go.uber.org/multierr"
@@ -113,34 +112,28 @@ func TestErrorEncoding(t *testing.T) {
113112
},
114113
{
115114
k: "k",
116-
iface: richErrors.WithMessage(errors.New("egad"), "failed"),
115+
iface: fmt.Errorf("failed: %w", errors.New("egad")),
117116
want: map[string]interface{}{
118-
"k": "failed: egad",
119-
"kVerbose": "egad\nfailed",
117+
"k": "failed: egad",
120118
},
121119
},
122120
{
123121
k: "error",
124122
iface: multierr.Combine(
125-
richErrors.WithMessage(
123+
fmt.Errorf("hello: %w",
126124
multierr.Combine(errors.New("foo"), errors.New("bar")),
127-
"hello",
128125
),
129126
errors.New("baz"),
130-
richErrors.WithMessage(errors.New("qux"), "world"),
127+
fmt.Errorf("world: %w", errors.New("qux")),
131128
),
132129
want: map[string]interface{}{
133130
"error": "hello: foo; bar; baz; world: qux",
134131
"errorCauses": []interface{}{
135132
map[string]interface{}{
136133
"error": "hello: foo; bar",
137-
"errorVerbose": "the following errors occurred:\n" +
138-
" - foo\n" +
139-
" - bar\n" +
140-
"hello",
141134
},
142135
map[string]interface{}{"error": "baz"},
143-
map[string]interface{}{"error": "world: qux", "errorVerbose": "qux\nworld"},
136+
map[string]interface{}{"error": "world: qux"},
144137
},
145138
},
146139
},
@@ -161,17 +154,10 @@ func TestErrorEncoding(t *testing.T) {
161154
func TestRichErrorSupport(t *testing.T) {
162155
f := Field{
163156
Type: ErrorType,
164-
Interface: richErrors.WithMessage(richErrors.New("egad"), "failed"),
157+
Interface: fmt.Errorf("failed: %w", errors.New("egad")),
165158
Key: "k",
166159
}
167160
enc := NewMapObjectEncoder()
168161
f.AddTo(enc)
169162
assert.Equal(t, "failed: egad", enc.Fields["k"], "Unexpected basic error message.")
170-
171-
serialized := enc.Fields["kVerbose"]
172-
// Don't assert the exact format used by a third-party package, but ensure
173-
// that some critical elements are present.
174-
assert.Regexp(t, `egad`, serialized, "Expected original error message to be present.")
175-
assert.Regexp(t, `failed`, serialized, "Expected error annotation to be present.")
176-
assert.Regexp(t, `TestRichErrorSupport`, serialized, "Expected calling function to be present in stacktrace.")
177163
}

0 commit comments

Comments
 (0)