Skip to content

Commit 47ff8cf

Browse files
committed
migrate errdefs package to github.com/containerd/errdefs module
This updates the errdefs package to be an alias for the new errdefs module. This helps transitioning consumers to the new module, and makes sure that containerd v2 and v1 use the same definitions. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 3a4de45 commit 47ff8cf

11 files changed

Lines changed: 392 additions & 120 deletions

File tree

errdefs/errdefs_deprecated.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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 defines the common errors used throughout containerd
18+
// packages.
19+
//
20+
// Use with fmt.Errorf to add context to an error.
21+
//
22+
// To detect an error class, use the IsXXX functions to tell whether an error
23+
// is of a certain type.
24+
//
25+
// The functions ToGRPC and FromGRPC can be used to map server-side and
26+
// client-side errors to the correct types.
27+
package errdefs
28+
29+
import (
30+
"github.com/containerd/errdefs"
31+
)
32+
33+
// Definitions of common error types used throughout containerd. All containerd
34+
// errors returned by most packages will map into one of these errors classes.
35+
// Packages should return errors of these types when they want to instruct a
36+
// client to take a particular action.
37+
//
38+
// For the most part, we just try to provide local grpc errors. Most conditions
39+
// map very well to those defined by grpc.
40+
var (
41+
ErrUnknown = errdefs.ErrUnknown
42+
ErrInvalidArgument = errdefs.ErrInvalidArgument
43+
ErrNotFound = errdefs.ErrNotFound
44+
ErrAlreadyExists = errdefs.ErrAlreadyExists
45+
ErrFailedPrecondition = errdefs.ErrFailedPrecondition
46+
ErrUnavailable = errdefs.ErrUnavailable
47+
ErrNotImplemented = errdefs.ErrNotImplemented
48+
)
49+
50+
// IsInvalidArgument returns true if the error is due to an invalid argument
51+
func IsInvalidArgument(err error) bool {
52+
return errdefs.IsInvalidArgument(err)
53+
}
54+
55+
// IsNotFound returns true if the error is due to a missing object
56+
func IsNotFound(err error) bool {
57+
return errdefs.IsNotFound(err)
58+
}
59+
60+
// IsAlreadyExists returns true if the error is due to an already existing
61+
// metadata item
62+
func IsAlreadyExists(err error) bool {
63+
return errdefs.IsAlreadyExists(err)
64+
}
65+
66+
// IsFailedPrecondition returns true if an operation could not proceed to the
67+
// lack of a particular condition
68+
func IsFailedPrecondition(err error) bool {
69+
return errdefs.IsFailedPrecondition(err)
70+
}
71+
72+
// IsUnavailable returns true if the error is due to a resource being unavailable
73+
func IsUnavailable(err error) bool {
74+
return errdefs.IsUnavailable(err)
75+
}
76+
77+
// IsNotImplemented returns true if the error is due to not being implemented
78+
func IsNotImplemented(err error) bool {
79+
return errdefs.IsNotImplemented(err)
80+
}
81+
82+
// IsCanceled returns true if the error is due to `context.Canceled`.
83+
func IsCanceled(err error) bool {
84+
return errdefs.IsCanceled(err)
85+
}
86+
87+
// IsDeadlineExceeded returns true if the error is due to
88+
// `context.DeadlineExceeded`.
89+
func IsDeadlineExceeded(err error) bool {
90+
return errdefs.IsDeadlineExceeded(err)
91+
}
92+
93+
// ToGRPC will attempt to map the backend containerd error into a grpc error,
94+
// using the original error message as a description.
95+
//
96+
// Further information may be extracted from certain errors depending on their
97+
// type.
98+
//
99+
// If the error is unmapped, the original error will be returned to be handled
100+
// by the regular grpc error handling stack.
101+
func ToGRPC(err error) error {
102+
return errdefs.ToGRPC(err)
103+
}
104+
105+
// ToGRPCf maps the error to grpc error codes, assembling the formatting string
106+
// and combining it with the target error string.
107+
//
108+
// This is equivalent to errdefs.ToGRPC(fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err))
109+
func ToGRPCf(err error, format string, args ...interface{}) error {
110+
return errdefs.ToGRPCf(err, format, args...)
111+
}
112+
113+
// FromGRPC returns the underlying error from a grpc service based on the grpc error code
114+
func FromGRPC(err error) error {
115+
return errdefs.FromGRPC(err)
116+
}

errdefs/grpc_test.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/containerd/cgroups/v3 v3.0.2
1414
github.com/containerd/console v1.0.3
1515
github.com/containerd/continuity v0.4.2
16+
github.com/containerd/errdefs v0.1.0
1617
github.com/containerd/fifo v1.1.0
1718
github.com/containerd/go-cni v1.1.9
1819
github.com/containerd/go-runc v1.0.0
@@ -68,8 +69,8 @@ require (
6869
go.opentelemetry.io/otel/trace v1.19.0
6970
golang.org/x/sync v0.3.0
7071
golang.org/x/sys v0.18.0
71-
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d
72-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d
72+
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13
73+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97
7374
google.golang.org/grpc v1.59.0
7475
google.golang.org/protobuf v1.33.0
7576
k8s.io/api v0.26.2
@@ -134,7 +135,7 @@ require (
134135
golang.org/x/text v0.14.0 // indirect
135136
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
136137
google.golang.org/appengine v1.6.7 // indirect
137-
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
138+
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
138139
gopkg.in/inf.v0 v0.9.1 // indirect
139140
gopkg.in/yaml.v2 v2.4.0 // indirect
140141
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKV
1414
cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
1515
cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
1616
cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
17-
cloud.google.com/go v0.110.7 h1:rJyC7nWRg2jWGZ4wSJ5nY65GTdYJkg0cd/uXb+ACI6o=
17+
cloud.google.com/go v0.110.8 h1:tyNdfIxjzaWctIiLYOTalaLKZ17SI44SKFW26QbOhME=
1818
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
1919
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
2020
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
@@ -169,6 +169,8 @@ github.com/containerd/continuity v0.0.0-20201208142359-180525291bb7/go.mod h1:kR
169169
github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EXlVlkqNba9rJe3j7w3Xa924itAMLgZH4UD/Q4PExuQ=
170170
github.com/containerd/continuity v0.4.2 h1:v3y/4Yz5jwnvqPKJJ+7Wf93fyWoCB3F5EclWG023MDM=
171171
github.com/containerd/continuity v0.4.2/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
172+
github.com/containerd/errdefs v0.1.0 h1:m0wCRBiu1WJT/Fr+iOoQHMQS/eP5myQ8lCv4Dz5ZURM=
173+
github.com/containerd/errdefs v0.1.0/go.mod h1:YgWiiHtLmSeBrvpw+UfPijzbLaB77mEG1WwJTDETIV0=
172174
github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
173175
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
174176
github.com/containerd/fifo v0.0.0-20200410184934-f15a3290365b/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0=
@@ -1140,12 +1142,12 @@ google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6D
11401142
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
11411143
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
11421144
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
1143-
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY=
1144-
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
1145-
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q=
1146-
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
1147-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
1148-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
1145+
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 h1:vlzZttNJGVqTsRFU9AmdnrcO1Znh8Ew9kCD//yjigk0=
1146+
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:CCviP9RmpZ1mxVr8MUjCnSiY09IbAXZxhLE6EhHIdPU=
1147+
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI=
1148+
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
1149+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0=
1150+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY=
11491151
google.golang.org/grpc v0.0.0-20160317175043-d3ddb4469d5a/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
11501152
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
11511153
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=

integration/client/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/cilium/ebpf v0.9.1 // indirect
3131
github.com/containerd/cgroups v1.1.0 // indirect
3232
github.com/containerd/console v1.0.3 // indirect
33+
github.com/containerd/errdefs v0.1.0 // indirect
3334
github.com/containerd/fifo v1.1.0 // indirect
3435
github.com/containerd/log v0.1.0 // indirect
3536
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
@@ -62,8 +63,8 @@ require (
6263
golang.org/x/net v0.23.0 // indirect
6364
golang.org/x/sync v0.3.0 // indirect
6465
golang.org/x/text v0.14.0 // indirect
65-
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
66-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
66+
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
67+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
6768
google.golang.org/grpc v1.59.0 // indirect
6869
google.golang.org/protobuf v1.33.0 // indirect
6970
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)