-
Notifications
You must be signed in to change notification settings - Fork 928
feat: propagate job error codes #6507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b77747b
bfa9140
e41136e
55f46b7
77d7d7d
43e6b7a
ee381ab
20fe286
d782120
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -41,6 +41,17 @@ type ProvisionerJobOptions struct { | |||||
Silent bool | ||||||
} | ||||||
|
||||||
type ProvisionerJobError struct { | ||||||
Message string | ||||||
Code codersdk.JobErrorCode | ||||||
} | ||||||
|
||||||
var _ error = new(ProvisionerJobError) | ||||||
|
||||||
func (err *ProvisionerJobError) Error() string { | ||||||
return err.Message | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an idea, could be useful sometime.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for suggestion, but this message will be shown in CLI or site, let's not scare the customer :) |
||||||
} | ||||||
|
||||||
// ProvisionerJob renders a provisioner job with interactive cancellation. | ||||||
func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOptions) error { | ||||||
if opts.FetchInterval == 0 { | ||||||
|
@@ -181,7 +192,10 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp | |||||
return nil | ||||||
case codersdk.ProvisionerJobFailed: | ||||||
} | ||||||
err = xerrors.New(job.Error) | ||||||
err = &ProvisionerJobError{ | ||||||
Message: job.Error, | ||||||
Code: job.ErrorCode, | ||||||
} | ||||||
jobMutex.Unlock() | ||||||
flushLogBuffer() | ||||||
return err | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE provisioner_jobs DROP COLUMN error_code; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE provisioner_jobs ADD COLUMN error_code text DEFAULT NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we potentially run into multiple errors? Would it make sense to store an array here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would stick to the |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ UPDATE | |
SET | ||
updated_at = $2, | ||
completed_at = $3, | ||
error = $4 | ||
error = $4, | ||
error_code = $5 | ||
WHERE | ||
id = $1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,14 @@ const ( | |
ProvisionerJobFailed ProvisionerJobStatus = "failed" | ||
) | ||
|
||
// JobErrorCode defines the error code returned by job runner. | ||
type JobErrorCode string | ||
|
||
const ( | ||
MissingTemplateParameter JobErrorCode = "MISSING_TEMPLATE_PARAMETER" | ||
RequiredTemplateVariables JobErrorCode = "REQUIRED_TEMPLATE_VARIABLES" | ||
) | ||
|
||
// ProvisionerJob describes the job executed by the provisioning daemon. | ||
type ProvisionerJob struct { | ||
ID uuid.UUID `json:"id" format:"uuid"` | ||
|
@@ -75,6 +83,7 @@ type ProvisionerJob struct { | |
CompletedAt *time.Time `json:"completed_at,omitempty" format:"date-time"` | ||
CanceledAt *time.Time `json:"canceled_at,omitempty" format:"date-time"` | ||
Error string `json:"error,omitempty"` | ||
ErrorCode JobErrorCode `json:"error_code,omitempty" enums:"MISSING_TEMPLATE_PARAMETER,REQUIRED_TEMPLATE_VARIABLES"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked it now - unfortunately, swaggo removed enum parts from the docs and |
||
Status ProvisionerJobStatus `json:"status" enums:"pending,running,succeeded,canceling,canceled,failed"` | ||
WorkerID *uuid.UUID `json:"worker_id,omitempty" format:"uuid"` | ||
FileID uuid.UUID `json:"file_id" format:"uuid"` | ||
|
Uh oh!
There was an error while loading. Please reload this page.