Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b87316

Browse files
authored
feat: propagate job error codes (#6507)
* feat: propagate job error_code* fix* Fix* Fix* Fix* add errors to typesGenerated* Address PR comments* Fix
1 parent524b14a commit3b87316

25 files changed

+406
-234
lines changed

‎cli/cliui/provisionerjob.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ type ProvisionerJobOptions struct {
4141
Silentbool
4242
}
4343

44+
typeProvisionerJobErrorstruct {
45+
Messagestring
46+
Code codersdk.JobErrorCode
47+
}
48+
49+
var_error=new(ProvisionerJobError)
50+
51+
func (err*ProvisionerJobError)Error()string {
52+
returnerr.Message
53+
}
54+
4455
// ProvisionerJob renders a provisioner job with interactive cancellation.
4556
funcProvisionerJob(ctx context.Context,writer io.Writer,optsProvisionerJobOptions)error {
4657
ifopts.FetchInterval==0 {
@@ -181,7 +192,10 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
181192
returnnil
182193
casecodersdk.ProvisionerJobFailed:
183194
}
184-
err=xerrors.New(job.Error)
195+
err=&ProvisionerJobError{
196+
Message:job.Error,
197+
Code:job.ErrorCode,
198+
}
185199
jobMutex.Unlock()
186200
flushLogBuffer()
187201
returnerr

‎cli/templatecreate.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"os"
@@ -196,7 +197,8 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
196197
},
197198
})
198199
iferr!=nil {
199-
if!provisionerd.IsMissingParameterError(err.Error()) {
200+
varjobErr*cliui.ProvisionerJobError
201+
iferrors.As(err,&jobErr)&&!provisionerd.IsMissingParameterErrorCode(string(jobErr.Code)) {
200202
returnnil,nil,err
201203
}
202204
}
@@ -233,7 +235,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
233235
}
234236
}
235237

236-
ifprovisionerd.IsMissingParameterError(version.Job.Error) {
238+
ifprovisionerd.IsMissingParameterErrorCode(string(version.Job.ErrorCode)) {
237239
valuesBySchemaID:=map[string]codersdk.ComputedParameter{}
238240
for_,parameterValue:=rangeparameterValues {
239241
valuesBySchemaID[parameterValue.SchemaID.String()]=parameterValue

‎coderd/apidoc/docs.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbfake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,6 +3512,7 @@ func (q *fakeQuerier) UpdateProvisionerJobWithCompleteByID(_ context.Context, ar
35123512
job.UpdatedAt=arg.UpdatedAt
35133513
job.CompletedAt=arg.CompletedAt
35143514
job.Error=arg.Error
3515+
job.ErrorCode=arg.ErrorCode
35153516
q.provisionerJobs[index]=job
35163517
returnnil
35173518
}

‎coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTERTABLE provisioner_jobs DROP COLUMN error_code;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTERTABLE provisioner_jobs ADD COLUMN error_codetext DEFAULTNULL;

‎coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/provisionerjobs.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ UPDATE
9191
SET
9292
updated_at= $2,
9393
completed_at= $3,
94-
error= $4
94+
error= $4,
95+
error_code= $5
9596
WHERE
9697
id= $1;

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func (server *Server) AcquireJob(ctx context.Context, _ *proto.Empty) (*proto.Ac
113113
String:errorMessage,
114114
Valid:true,
115115
},
116+
ErrorCode:job.ErrorCode,
116117
})
117118
iferr!=nil {
118119
returnxerrors.Errorf("update provisioner job: %w",err)
@@ -639,12 +640,17 @@ func (server *Server) FailJob(ctx context.Context, failJob *proto.FailedJob) (*p
639640
String:failJob.Error,
640641
Valid:failJob.Error!="",
641642
}
643+
job.ErrorCode= sql.NullString{
644+
String:failJob.ErrorCode,
645+
Valid:failJob.ErrorCode!="",
646+
}
642647

643648
err=server.Database.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
644649
ID:jobID,
645650
CompletedAt:job.CompletedAt,
646651
UpdatedAt:database.Now(),
647652
Error:job.Error,
653+
ErrorCode:job.ErrorCode,
648654
})
649655
iferr!=nil {
650656
returnnil,xerrors.Errorf("update provisioner job: %w",err)

‎coderd/provisionerjobs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ func convertProvisionerJob(provisionerJob database.ProvisionerJob) codersdk.Prov
317317
ID:provisionerJob.ID,
318318
CreatedAt:provisionerJob.CreatedAt,
319319
Error:provisionerJob.Error.String,
320+
ErrorCode:codersdk.JobErrorCode(provisionerJob.ErrorCode.String),
320321
FileID:provisionerJob.FileID,
321322
Tags:provisionerJob.Tags,
322323
}

‎codersdk/provisionerdaemons.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ const (
6767
ProvisionerJobFailedProvisionerJobStatus="failed"
6868
)
6969

70+
// JobErrorCode defines the error code returned by job runner.
71+
typeJobErrorCodestring
72+
73+
const (
74+
MissingTemplateParameterJobErrorCode="MISSING_TEMPLATE_PARAMETER"
75+
RequiredTemplateVariablesJobErrorCode="REQUIRED_TEMPLATE_VARIABLES"
76+
)
77+
7078
// ProvisionerJob describes the job executed by the provisioning daemon.
7179
typeProvisionerJobstruct {
7280
ID uuid.UUID`json:"id" format:"uuid"`
@@ -75,6 +83,7 @@ type ProvisionerJob struct {
7583
CompletedAt*time.Time`json:"completed_at,omitempty" format:"date-time"`
7684
CanceledAt*time.Time`json:"canceled_at,omitempty" format:"date-time"`
7785
Errorstring`json:"error,omitempty"`
86+
ErrorCodeJobErrorCode`json:"error_code,omitempty" enums:"MISSING_TEMPLATE_PARAMETER,REQUIRED_TEMPLATE_VARIABLES"`
7887
StatusProvisionerJobStatus`json:"status" enums:"pending,running,succeeded,canceling,canceled,failed"`
7988
WorkerID*uuid.UUID`json:"worker_id,omitempty" format:"uuid"`
8089
FileID uuid.UUID`json:"file_id" format:"uuid"`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp