forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
341 lines (272 loc) · 9.62 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Copyright 2014-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
package dockerapi
import (
"time"
"github.com/aws/amazon-ecs-agent/agent/dockerclient"
)
const (
// DockerTimeoutErrorName is the name of docker timeout error.
DockerTimeoutErrorName = "DockerTimeoutError"
// CannotInspectContainerErrorName is the name of container inspect error.
CannotInspectContainerErrorName = "CannotInspectContainerError"
// CannotStartContainerErrorName is the name of container start error.
CannotStartContainerErrorName = "CannotStartContainerError"
// CannotDescribeContainerErrorName is the name of describe container error.
CannotDescribeContainerErrorName = "CannotDescribeContainerError"
)
// DockerTimeoutError is an error type for describing timeouts
type DockerTimeoutError struct {
// Duration is the timeout period.
Duration time.Duration
// Transition is the description of operation that timed out.
Transition string
}
func (err *DockerTimeoutError) Error() string {
return "Could not transition to " + err.Transition + "; timed out after waiting " + err.Duration.String()
}
// ErrorName returns the name of the error
func (err *DockerTimeoutError) ErrorName() string { return DockerTimeoutErrorName }
// OutOfMemoryError is a type for errors caused by running out of memory
type OutOfMemoryError struct{}
func (err OutOfMemoryError) Error() string { return "Container killed due to memory usage" }
// ErrorName returns the name of the error
func (err OutOfMemoryError) ErrorName() string { return "OutOfMemoryError" }
// DockerStateError is a wrapper around the error docker puts in the '.State.Error' field of its inspect output.
type DockerStateError struct {
dockerError string
name string
}
// NewDockerStateError creates a DockerStateError
func NewDockerStateError(err string) DockerStateError {
// Add stringmatching logic as needed to provide better output than docker
return DockerStateError{
dockerError: err,
name: "DockerStateError",
}
}
func (err DockerStateError) Error() string {
return err.dockerError
}
// ErrorName returns the name of the DockerStateError.
func (err DockerStateError) ErrorName() string {
return err.name
}
// CannotGetDockerClientError is a type for failing to get a specific Docker client
type CannotGetDockerClientError struct {
version dockerclient.DockerVersion
err error
}
func (c CannotGetDockerClientError) Error() string {
if c.version != "" {
return "(v" + string(c.version) + ") - " + c.err.Error()
}
return c.err.Error()
}
// ErrorName returns the name of the CannotGetDockerClientError.
func (CannotGetDockerClientError) ErrorName() string {
return "CannotGetDockerclientError"
}
// CannotStopContainerError indicates any error when trying to stop a container
type CannotStopContainerError struct {
FromError error
}
func (err CannotStopContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotStopContainerError.
func (err CannotStopContainerError) ErrorName() string {
return "CannotStopContainerError"
}
// IsRetriableError returns a boolean indicating whether the call that
// generated the error can be retried.
// When stopping a container, most errors that we can get should be
// considered retriable. However, in the case where the container is
// already stopped or doesn't exist at all, there's no sense in
// retrying.
func (err CannotStopContainerError) IsRetriableError() bool {
if _, ok := err.FromError.(NoSuchContainerError); ok {
return false
}
return true
}
// CannotPullContainerError indicates any error when trying to pull
// a container image
type CannotPullContainerError struct {
FromError error
}
func (err CannotPullContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotPullContainerError.
func (err CannotPullContainerError) ErrorName() string {
return "CannotPullContainerError"
}
// CannotPullECRContainerError indicates any error when trying to pull
// a container image from ECR
type CannotPullECRContainerError struct {
FromError error
}
func (err CannotPullECRContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotPullECRContainerError.
func (err CannotPullECRContainerError) ErrorName() string {
return "CannotPullECRContainerError"
}
// Retry fulfills the utils.Retrier interface and allows retries to be skipped by utils.Retry* functions
func (err CannotPullECRContainerError) Retry() bool {
return false
}
// CannotPullContainerAuthError indicates any error when trying to pull
// a container image
type CannotPullContainerAuthError struct {
FromError error
}
func (err CannotPullContainerAuthError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotPullContainerAuthError.
func (err CannotPullContainerAuthError) ErrorName() string {
return "CannotPullContainerAuthError"
}
// Retry fulfills the utils.Retrier interface and allows retries to be skipped by utils.Retry* functions
func (err CannotPullContainerAuthError) Retry() bool {
return false
}
// CannotCreateContainerError indicates any error when trying to create a container
type CannotCreateContainerError struct {
FromError error
}
func (err CannotCreateContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotCreateContainerError.
func (err CannotCreateContainerError) ErrorName() string {
return "CannotCreateContainerError"
}
// CannotStartContainerError indicates any error when trying to start a container
type CannotStartContainerError struct {
FromError error
}
func (err CannotStartContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotStartContainerError
func (err CannotStartContainerError) ErrorName() string {
return CannotStartContainerErrorName
}
// CannotInspectContainerError indicates any error when trying to inspect a container
type CannotInspectContainerError struct {
FromError error
}
func (err CannotInspectContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotInspectContainerError
func (err CannotInspectContainerError) ErrorName() string {
return CannotInspectContainerErrorName
}
// CannotRemoveContainerError indicates any error when trying to remove a container
type CannotRemoveContainerError struct {
FromError error
}
func (err CannotRemoveContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotRemoveContainerError
func (err CannotRemoveContainerError) ErrorName() string {
return "CannotRemoveContainerError"
}
// CannotDescribeContainerError indicates any error when trying to describe a container
type CannotDescribeContainerError struct {
FromError error
}
func (err CannotDescribeContainerError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotDescribeContainerError
func (err CannotDescribeContainerError) ErrorName() string {
return CannotDescribeContainerErrorName
}
// CannotListContainersError indicates any error when trying to list containers
type CannotListContainersError struct {
FromError error
}
func (err CannotListContainersError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotListContainersError
func (err CannotListContainersError) ErrorName() string {
return "CannotListContainersError"
}
type CannotListImagesError struct {
FromError error
}
func (err CannotListImagesError) Error() string {
return err.FromError.Error()
}
// ErrorName returns name of the CannotListImagesError
func (err CannotListImagesError) ErrorName() string {
return "CannotListImagesError"
}
// CannotCreateVolumeError indicates any error when trying to create a volume
type CannotCreateVolumeError struct {
fromError error
}
func (err CannotCreateVolumeError) Error() string {
return err.fromError.Error()
}
func (err CannotCreateVolumeError) ErrorName() string {
return "CannotCreateVolumeError"
}
// CannotInspectVolumeError indicates any error when trying to inspect a volume
type CannotInspectVolumeError struct {
fromError error
}
func (err CannotInspectVolumeError) Error() string {
return err.fromError.Error()
}
func (err CannotInspectVolumeError) ErrorName() string {
return "CannotInspectVolumeError"
}
// CannotRemoveVolumeError indicates any error when trying to inspect a volume
type CannotRemoveVolumeError struct {
fromError error
}
func (err CannotRemoveVolumeError) Error() string {
return err.fromError.Error()
}
func (err CannotRemoveVolumeError) ErrorName() string {
return "CannotRemoveVolumeError"
}
// CannotListPluginsError indicates any error when trying to list docker plugins
type CannotListPluginsError struct {
fromError error
}
func (err CannotListPluginsError) Error() string {
return err.fromError.Error()
}
func (err CannotListPluginsError) ErrorName() string {
return "CannotListPluginsError"
}
// NoSuchContainerError indicates error when a given container is not found.
type NoSuchContainerError struct {
ID string
}
func (err NoSuchContainerError) Error() string {
return "Container not found: " + err.ID
}
func (err NoSuchContainerError) ErrorName() string {
return "NoSuchContainerError"
}