Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 8aa47d3

Browse files
committed
panic and errors processing fixes
1 parent 52c86ec commit 8aa47d3

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

pkg/api/services/repohook/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (s BasicService) handleGithubPullRequestWebhook(rc *request.AnonymousContex
137137
})
138138
if commitErr != nil {
139139
if commitErr == provider.ErrUnauthorized || commitErr == provider.ErrNotFound {
140-
rc.Log.Warnf("Can't set github commit status to '%s' for repo %s and commit %s, skipping webhook: %s",
140+
rc.Log.Infof("Can't set github commit status to '%s' for repo %s and commit %s, skipping webhook: %s",
141141
desc, repo.FullNameWithProvider(), ev.Head.CommitSHA, commitErr)
142142
return errSkipWehbook
143143
}

pkg/worker/lib/executors/fargate.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ func (f Fargate) runTask(ctx context.Context, req *Requirements) (*ecs.Task, err
9595
}
9696

9797
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)
9999
}
100100

101101
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)
103103
}
104104

105105
return res.Tasks[0], nil
@@ -117,11 +117,11 @@ func (f Fargate) describeTask(ctx context.Context) (*ecs.Task, error) {
117117
}
118118

119119
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)
121121
}
122122

123123
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)
125125
}
126126

127127
return res.Tasks[0], nil
@@ -135,7 +135,7 @@ func (f *Fargate) waitForContainerStart(ctx context.Context) (*ecs.Task, error)
135135
}
136136

137137
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")
139139
}
140140

141141
switch *task.LastStatus {
@@ -146,9 +146,9 @@ func (f *Fargate) waitForContainerStart(ctx context.Context) (*ecs.Task, error)
146146
f.log.Infof("Container started")
147147
return task, nil
148148
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)
150150
default:
151-
return nil, fmt.Errorf("unknown task status %s", *task.LastStatus)
151+
return nil, errors.Wrapf(ErrExecutorFail, "unknown task status %s", *task.LastStatus)
152152
}
153153
}
154154
}
@@ -159,19 +159,19 @@ func (f *Fargate) describeNetworkInterface(ctx context.Context, networkInterface
159159
}
160160
res, err := f.ec2.DescribeNetworkInterfacesWithContext(ctx, &input)
161161
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)
163163
}
164164

165165
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)
167167
}
168168

169169
return res.NetworkInterfaces[0], nil
170170
}
171171

172172
func (f *Fargate) getTaskPublicIP(ctx context.Context, task *ecs.Task) (string, error) {
173173
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)
175175
}
176176

177177
attach := task.Attachments[0]
@@ -183,7 +183,7 @@ func (f *Fargate) getTaskPublicIP(ctx context.Context, task *ecs.Task) (string,
183183
}
184184
}
185185
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)
187187
}
188188

189189
ni, err := f.describeNetworkInterface(ctx, networkInterfaceID)
@@ -192,11 +192,11 @@ func (f *Fargate) getTaskPublicIP(ctx context.Context, task *ecs.Task) (string,
192192
}
193193

194194
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)
196196
}
197197

198198
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)
200200
}
201201

202202
return *ni.Association.PublicIp, nil
@@ -218,7 +218,7 @@ func (f *Fargate) Setup(ctx context.Context, req *Requirements) error {
218218
}
219219

220220
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)
222222
}
223223
f.taskID = *task.TaskArn
224224

@@ -248,7 +248,7 @@ func (f Fargate) Run(ctx context.Context, name string, args ...string) (*RunResu
248248
}
249249
now := time.Now()
250250
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")
252252
}
253253

254254
req := build.Request{
@@ -280,12 +280,13 @@ func (f Fargate) runBuildCommand(ctx context.Context, req *build.Request) (*RunR
280280
}
281281

282282
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)
284284
}
285285

286286
res := RunResult(buildResp.RequestResult)
287287

288288
if buildResp.CommandError != "" {
289+
// no wrapping of ErrExecutorFail
289290
return &res, fmt.Errorf("build command for req %#v complete with error: %s",
290291
req, buildResp.CommandError)
291292
}
@@ -311,6 +312,11 @@ func (f Fargate) CopyFile(ctx context.Context, dst, src string) error {
311312
}
312313

313314
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+
314320
_, err := f.ecs.StopTask(&ecs.StopTaskInput{
315321
Cluster: aws.String(f.cfg.GetString("FARGATE_CLUSTER")),
316322
Task: aws.String(f.taskID),

0 commit comments

Comments
 (0)