@@ -95,11 +95,11 @@ func (f Fargate) runTask(ctx context.Context, req *Requirements) (*ecs.Task, err
95
95
}
96
96
97
97
if len (res .Failures ) != 0 {
98
- return nil , errors .Wrapf (f . wrapExecutorError ( err ) , "failures during running aws fargate task: %#v" , res .Failures )
98
+ return nil , errors .Wrapf (ErrExecutorFail , "failures during running aws fargate task: %#v" , res .Failures )
99
99
}
100
100
101
101
if len (res .Tasks ) != 1 {
102
- return nil , errors .Wrapf (f . wrapExecutorError ( err ) , "res.Tasks count != 1: %#v" , res .Tasks )
102
+ return nil , errors .Wrapf (ErrExecutorFail , "res.Tasks count != 1: %#v" , res .Tasks )
103
103
}
104
104
105
105
return res .Tasks [0 ], nil
@@ -117,11 +117,11 @@ func (f Fargate) describeTask(ctx context.Context) (*ecs.Task, error) {
117
117
}
118
118
119
119
if len (res .Failures ) != 0 {
120
- return nil , errors .Wrapf (f . wrapExecutorError ( err ) , "failures during running aws fargate task: %#v" , res .Failures )
120
+ return nil , errors .Wrapf (ErrExecutorFail , "failures during running aws fargate task: %#v" , res .Failures )
121
121
}
122
122
123
123
if len (res .Tasks ) != 1 {
124
- return nil , errors .Wrapf (f . wrapExecutorError ( err ) , "res.Tasks count != 1: %#v" , res .Tasks )
124
+ return nil , errors .Wrapf (ErrExecutorFail , "res.Tasks count != 1: %#v" , res .Tasks )
125
125
}
126
126
127
127
return res .Tasks [0 ], nil
@@ -135,7 +135,7 @@ func (f *Fargate) waitForContainerStart(ctx context.Context) (*ecs.Task, error)
135
135
}
136
136
137
137
if task .LastStatus == nil {
138
- return nil , fmt . Errorf ( "failed to get task last status" )
138
+ return nil , errors . Wrap ( ErrExecutorFail , "failed to get task last status" )
139
139
}
140
140
141
141
switch * task .LastStatus {
@@ -146,9 +146,9 @@ func (f *Fargate) waitForContainerStart(ctx context.Context) (*ecs.Task, error)
146
146
f .log .Infof ("Container started" )
147
147
return task , nil
148
148
case "DEACTIVATING" , "STOPPING" , "DEPROVISIONING" , "STOPPED" :
149
- return nil , fmt . Errorf ( "container is stopped or stopping: %s" , * task .LastStatus )
149
+ return nil , errors . Wrapf ( ErrExecutorFail , "container is stopped or stopping: %s" , * task .LastStatus )
150
150
default :
151
- return nil , fmt . Errorf ( "unknown task status %s" , * task .LastStatus )
151
+ return nil , errors . Wrapf ( ErrExecutorFail , "unknown task status %s" , * task .LastStatus )
152
152
}
153
153
}
154
154
}
@@ -159,19 +159,19 @@ func (f *Fargate) describeNetworkInterface(ctx context.Context, networkInterface
159
159
}
160
160
res , err := f .ec2 .DescribeNetworkInterfacesWithContext (ctx , & input )
161
161
if err != nil {
162
- return nil , errors .Wrapf (err , "failed to describe network interface %s" , networkInterfaceID )
162
+ return nil , errors .Wrapf (f . wrapExecutorError ( err ) , "failed to describe network interface %s" , networkInterfaceID )
163
163
}
164
164
165
165
if len (res .NetworkInterfaces ) != 1 {
166
- return nil , fmt . Errorf ( "len(res.NetworkInterfaces) != 1: %#v" , res .NetworkInterfaces )
166
+ return nil , errors . Wrapf ( ErrExecutorFail , "len(res.NetworkInterfaces) != 1: %#v" , res .NetworkInterfaces )
167
167
}
168
168
169
169
return res .NetworkInterfaces [0 ], nil
170
170
}
171
171
172
172
func (f * Fargate ) getTaskPublicIP (ctx context.Context , task * ecs.Task ) (string , error ) {
173
173
if len (task .Attachments ) != 1 {
174
- return "" , fmt . Errorf ( "len(task.Attachments) != 1: %#v" , task .Attachments )
174
+ return "" , errors . Wrapf ( ErrExecutorFail , "len(task.Attachments) != 1: %#v" , task .Attachments )
175
175
}
176
176
177
177
attach := task .Attachments [0 ]
@@ -183,7 +183,7 @@ func (f *Fargate) getTaskPublicIP(ctx context.Context, task *ecs.Task) (string,
183
183
}
184
184
}
185
185
if networkInterfaceID == "" {
186
- return "" , fmt . Errorf ( "no networkInterfaceId in attachment details: %#v" , attach )
186
+ return "" , errors . Wrapf ( ErrExecutorFail , "no networkInterfaceId in attachment details: %#v" , attach )
187
187
}
188
188
189
189
ni , err := f .describeNetworkInterface (ctx , networkInterfaceID )
@@ -192,11 +192,11 @@ func (f *Fargate) getTaskPublicIP(ctx context.Context, task *ecs.Task) (string,
192
192
}
193
193
194
194
if ni .Association == nil {
195
- return "" , fmt . Errorf ( "no association in network interface %#v" , ni )
195
+ return "" , errors . Wrapf ( ErrExecutorFail , "no association in network interface %#v" , ni )
196
196
}
197
197
198
198
if ni .Association .PublicIp == nil {
199
- return "" , fmt . Errorf ( "no public ip in network interface %#v" , ni )
199
+ return "" , errors . Wrapf ( ErrExecutorFail , "no public ip in network interface %#v" , ni )
200
200
}
201
201
202
202
return * ni .Association .PublicIp , nil
@@ -218,7 +218,7 @@ func (f *Fargate) Setup(ctx context.Context, req *Requirements) error {
218
218
}
219
219
220
220
if task .TaskArn == nil {
221
- return fmt . Errorf ( "no arn in task %#v" , task )
221
+ return errors . Wrapf ( ErrExecutorFail , "no arn in task %#v" , task )
222
222
}
223
223
f .taskID = * task .TaskArn
224
224
@@ -248,7 +248,7 @@ func (f Fargate) Run(ctx context.Context, name string, args ...string) (*RunResu
248
248
}
249
249
now := time .Now ()
250
250
if deadline .Before (now ) {
251
- return nil , errors .New ( "deadline exceeded: it's before now" )
251
+ return nil , errors .Wrap ( ErrExecutorFail , "deadline exceeded: it's before now" )
252
252
}
253
253
254
254
req := build.Request {
@@ -280,12 +280,13 @@ func (f Fargate) runBuildCommand(ctx context.Context, req *build.Request) (*RunR
280
280
}
281
281
282
282
if buildResp .Error != "" {
283
- return nil , f . wrapExecutorError ( fmt . Errorf ( "failed to run build command with req %#v: %s" , req , buildResp .Error ) )
283
+ return nil , errors . Wrapf ( ErrExecutorFail , "failed to run build command with req %#v: %s" , req , buildResp .Error )
284
284
}
285
285
286
286
res := RunResult (buildResp .RequestResult )
287
287
288
288
if buildResp .CommandError != "" {
289
+ // no wrapping of ErrExecutorFail
289
290
return & res , fmt .Errorf ("build command for req %#v complete with error: %s" ,
290
291
req , buildResp .CommandError )
291
292
}
@@ -311,6 +312,11 @@ func (f Fargate) CopyFile(ctx context.Context, dst, src string) error {
311
312
}
312
313
313
314
func (f Fargate ) Clean () {
315
+ if f .taskID == "" {
316
+ f .log .Infof ("No need to stop fargate task: taskID is empty" )
317
+ return
318
+ }
319
+
314
320
_ , err := f .ecs .StopTask (& ecs.StopTaskInput {
315
321
Cluster : aws .String (f .cfg .GetString ("FARGATE_CLUSTER" )),
316
322
Task : aws .String (f .taskID ),
0 commit comments