Skip to content

Commit d8d2720

Browse files
committed
Revert "migrate errdefs package to github.com/containerd/errdefs module"
This reverts commit 47ff8cf. Signed-off-by: Derek McGowan <[email protected]>
1 parent e82d201 commit d8d2720

File tree

11 files changed

+103
-329
lines changed

11 files changed

+103
-329
lines changed

errdefs/errdefs_deprecated.go

Lines changed: 0 additions & 116 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

errdefs/grpc_test.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package errdefs
18+
19+
import (
20+
"context"
21+
"errors"
22+
"fmt"
23+
"testing"
24+
25+
"google.golang.org/grpc/codes"
26+
"google.golang.org/grpc/status"
27+
)
28+
29+
func TestGRPCRoundTrip(t *testing.T) {
30+
errShouldLeaveAlone := errors.New("unknown to package")
31+
32+
for _, testcase := range []struct {
33+
input error
34+
cause error
35+
str string
36+
}{
37+
{
38+
input: ErrAlreadyExists,
39+
cause: ErrAlreadyExists,
40+
},
41+
{
42+
input: ErrNotFound,
43+
cause: ErrNotFound,
44+
},
45+
//nolint:dupword
46+
{
47+
input: fmt.Errorf("test test test: %w", ErrFailedPrecondition),
48+
cause: ErrFailedPrecondition,
49+
str: "test test test: failed precondition",
50+
},
51+
{
52+
input: status.Errorf(codes.Unavailable, "should be not available"),
53+
cause: ErrUnavailable,
54+
str: "should be not available: unavailable",
55+
},
56+
{
57+
input: errShouldLeaveAlone,
58+
cause: ErrUnknown,
59+
str: errShouldLeaveAlone.Error() + ": " + ErrUnknown.Error(),
60+
},
61+
{
62+
input: context.Canceled,
63+
cause: context.Canceled,
64+
str: "context canceled",
65+
},
66+
{
67+
input: fmt.Errorf("this is a test cancel: %w", context.Canceled),
68+
cause: context.Canceled,
69+
str: "this is a test cancel: context canceled",
70+
},
71+
{
72+
input: context.DeadlineExceeded,
73+
cause: context.DeadlineExceeded,
74+
str: "context deadline exceeded",
75+
},
76+
{
77+
input: fmt.Errorf("this is a test deadline exceeded: %w", context.DeadlineExceeded),
78+
cause: context.DeadlineExceeded,
79+
str: "this is a test deadline exceeded: context deadline exceeded",
80+
},
81+
} {
82+
t.Run(testcase.input.Error(), func(t *testing.T) {
83+
t.Logf("input: %v", testcase.input)
84+
gerr := ToGRPC(testcase.input)
85+
t.Logf("grpc: %v", gerr)
86+
ferr := FromGRPC(gerr)
87+
t.Logf("recovered: %v", ferr)
88+
89+
if !errors.Is(ferr, testcase.cause) {
90+
t.Fatalf("unexpected cause: !errors.Is(%v, %v)", ferr, testcase.cause)
91+
}
92+
93+
expected := testcase.str
94+
if expected == "" {
95+
expected = testcase.cause.Error()
96+
}
97+
if ferr.Error() != expected {
98+
t.Fatalf("unexpected string: %q != %q", ferr.Error(), expected)
99+
}
100+
})
101+
}
102+
103+
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ require (
1414
github.com/containerd/console v1.0.3
1515
github.com/containerd/containerd/api v1.7.19
1616
github.com/containerd/continuity v0.4.2
17-
github.com/containerd/errdefs v0.1.0
1817
github.com/containerd/fifo v1.1.0
1918
github.com/containerd/go-cni v1.1.9
2019
github.com/containerd/go-runc v1.0.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ github.com/containerd/continuity v0.0.0-20201208142359-180525291bb7/go.mod h1:kR
171171
github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EXlVlkqNba9rJe3j7w3Xa924itAMLgZH4UD/Q4PExuQ=
172172
github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM=
173173
github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
174-
github.com/containerd/errdefs v0.1.0 h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5ZURM=
175-
github.com/containerd/errdefs v0.1.0/go.mod h1:YgWiiHtLmSeBrvpw+UfPijzbLaB77mEG1WwJTDETIV0=
176174
github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
177175
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
178176
github.com/containerd/fifo v0.0.0-20200410184934-f15a3290365b/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0=

integration/client/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ require (
3232
github.com/cilium/ebpf v0.9.1 // indirect
3333
github.com/containerd/cgroups v1.1.0 // indirect
3434
github.com/containerd/console v1.0.3 // indirect
35-
github.com/containerd/errdefs v0.1.0 // indirect
3635
github.com/containerd/fifo v1.1.0 // indirect
3736
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3837
github.com/davecgh/go-spew v1.1.1 // indirect

integration/client/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,6 @@ github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EX
13041304
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
13051305
github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM=
13061306
github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
1307-
github.com/containerd/errdefs v0.1.0 h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5ZURM=
1308-
github.com/containerd/errdefs v0.1.0/go.mod h1:YgWiiHtLmSeBrvpw+UfPijzbLaB77mEG1WwJTDETIV0=
13091307
github.com/containerd/fifo v1.0.0/go.mod h1:ocF/ME1SX5b1AOlWi9r677YJmCPSwwWnQ9O123vzpE4=
13101308
github.com/containerd/fifo v1.1.0 h1:4I2mbh5stb1u6ycIABlBw9zgtlK8viPI9QkQNRQEEmY=
13111309
github.com/containerd/fifo v1.1.0/go.mod h1:bmC4NWMbXlt2EZ0Hc7Fx7QzTFxgPID13eH0Qu+MAb2o=

0 commit comments

Comments
 (0)