-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy patherrors.go
257 lines (202 loc) · 7.14 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
// Copyright 2014-2017 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 engine
import (
"time"
"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerclient"
docker "github.com/fsouza/go-dockerclient"
)
const dockerTimeoutErrorName = "DockerTimeoutError"
// engineError wraps the error interface with an identifier method that
// is used to classify the error type
type engineError interface {
error
ErrorName() string
}
// impossibleTransitionError is an error that occurs when an event causes a
// container to try and transition to a state that it cannot be moved to
type impossibleTransitionError struct {
state api.ContainerStatus
}
func (err *impossibleTransitionError) Error() string {
return "Cannot transition to " + err.state.String()
}
func (err *impossibleTransitionError) ErrorName() string { return "ImpossibleStateTransitionError" }
// DockerTimeoutError is an error type for describing timeouts
type DockerTimeoutError struct {
duration time.Duration
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 }
// ContainerVanishedError is a type for describing a container that does not exist
type ContainerVanishedError struct{}
func (err ContainerVanishedError) Error() string { return "No container matching saved ID found" }
// ErrorName returns the name of the error
func (err ContainerVanishedError) ErrorName() string { return "ContainerVanishedError" }
// 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 error
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 error
func (CannotGetDockerClientError) ErrorName() string {
return "CannotGetDockerclientError"
}
// TaskStoppedBeforePullBeginError is a type for task errors involving pull
type TaskStoppedBeforePullBeginError struct {
taskArn string
}
func (err TaskStoppedBeforePullBeginError) Error() string {
return "Task stopped before image pull could begin for task: " + err.taskArn
}
// ErrorName returns the name of the error
func (TaskStoppedBeforePullBeginError) ErrorName() string {
return "TaskStoppedBeforePullBeginError"
}
// CannotStopContainerError indicates any error when trying to stop a container
type CannotStopContainerError struct {
fromError error
}
func (err CannotStopContainerError) Error() string {
return err.fromError.Error()
}
func (err CannotStopContainerError) ErrorName() string {
return "CannotStopContainerError"
}
func (err CannotStopContainerError) IsUnretriableError() bool {
if _, ok := err.fromError.(*docker.NoSuchContainer); ok {
return true
}
if _, ok := err.fromError.(*docker.ContainerNotRunning); ok {
return true
}
return false
}
// 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()
}
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()
}
func (err CannotPullECRContainerError) ErrorName() string {
return "CannotPullECRContainerError"
}
// CannotCreateContainerError indicates any error when trying to create a container
type CannotCreateContainerError struct {
fromError error
}
func (err CannotCreateContainerError) Error() string {
return err.fromError.Error()
}
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()
}
func (err CannotStartContainerError) ErrorName() string {
return "CannotStartContainerError"
}
// CannotInspectContainerError indicates any error when trying to inspect a container
type CannotInspectContainerError struct {
fromError error
}
func (err CannotInspectContainerError) Error() string {
return err.fromError.Error()
}
func (err CannotInspectContainerError) ErrorName() string {
return "CannotInspectContainerError"
}
// CannotRemoveContainerError indicates any error when trying to remove a container
type CannotRemoveContainerError struct {
fromError error
}
func (err CannotRemoveContainerError) Error() string {
return err.fromError.Error()
}
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()
}
func (err CannotDescribeContainerError) ErrorName() string {
return "CannotDescribeContainerError"
}
// CannotListContainersError indicates any error when trying to list containers
type CannotListContainersError struct {
fromError error
}
func (err CannotListContainersError) Error() string {
return err.fromError.Error()
}
func (err CannotListContainersError) ErrorName() string {
return "CannotListContainersError"
}