-
Notifications
You must be signed in to change notification settings - Fork 901
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 1 commit
b77747b
bfa9140
e41136e
55f46b7
77d7d7d
43e6b7a
ee381ab
20fe286
d782120
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,18 +42,14 @@ type ProvisionerJobOptions struct { | |||||
} | ||||||
|
||||||
type ProvisionerJobError struct { | ||||||
message string | ||||||
code codersdk.JobErrorCode | ||||||
Message string | ||||||
Code codersdk.JobErrorCode | ||||||
} | ||||||
|
||||||
var _ error = new(ProvisionerJobError) | ||||||
|
||||||
func (err *ProvisionerJobError) Error() string { | ||||||
return err.message | ||||||
} | ||||||
|
||||||
func (err *ProvisionerJobError) Code() codersdk.JobErrorCode { | ||||||
return err.code | ||||||
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. | ||||||
|
@@ -197,8 +193,8 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp | |||||
case codersdk.ProvisionerJobFailed: | ||||||
} | ||||||
err = &ProvisionerJobError{ | ||||||
message: job.Error, | ||||||
code: job.ErrorCode, | ||||||
Message: job.Error, | ||||||
Code: job.ErrorCode, | ||||||
} | ||||||
jobMutex.Unlock() | ||||||
flushLogBuffer() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,11 @@ const ( | |
requiredTemplateVariablesErrorText = "required template variables" | ||
) | ||
|
||
var errorCodes = map[string]string{ | ||
MissingParameterErrorCode: missingParameterErrorText, | ||
RequiredTemplateVariablesErrorCode: requiredTemplateVariablesErrorText, | ||
} | ||
|
||
var errUpdateSkipped = xerrors.New("update skipped; job complete or failed") | ||
|
||
type Runner struct { | ||
|
@@ -1058,10 +1063,11 @@ func (r *Runner) failedJobf(format string, args ...interface{}) *proto.FailedJob | |
message := fmt.Sprintf(format, args...) | ||
var code string | ||
|
||
if strings.Contains(message, missingParameterErrorText) { | ||
code = MissingParameterErrorCode | ||
} else if strings.Contains(message, requiredTemplateVariablesErrorText) { | ||
code = RequiredTemplateVariablesErrorCode | ||
for c, m := range errorCodes { | ||
if strings.Contains(message, m) { | ||
code = c | ||
break | ||
} | ||
} | ||
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. This format seems like it'd be easy to miss, e.g. when adding new error messages/codes. How about storing them in a map and iterating over it here? var errorCodes = map[string]string{
MissingParameterErrorCode: missingParameterErrorText,
// ...
}
for c, m := range errorCodes {
// ...
} Ultimately though, this logic is a bit hidden behind a "print function", it might be a good idea to refactor so that it can accept an 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. Good idea with the map, added.
This is risky, as it would require refactoring of interfaces, and I'm sure that I don't want to deal with it now... |
||
return &proto.FailedJob{ | ||
JobId: r.job.JobId, | ||
|
Uh oh!
There was an error while loading. Please reload this page.