- Notifications
You must be signed in to change notification settings - Fork1.1k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
b77747bbfa9140e41136e55f46b777d7d7d43e6b7aee381ab20fe286d782120File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -41,6 +41,21 @@ type ProvisionerJobOptions struct { | ||
| Silent bool | ||
| } | ||
| type ProvisionerJobError struct { | ||
| message string | ||
| code string | ||
| } | ||
mtojek marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| var _ error = new(ProvisionerJobError) | ||
| func (err *ProvisionerJobError) Error() string { | ||
| return err.message | ||
| } | ||
| func (err *ProvisionerJobError) Code() string { | ||
| return err.code | ||
| } | ||
| // 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 +196,10 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp | ||
| return nil | ||
| case codersdk.ProvisionerJobFailed: | ||
| } | ||
| err = &ProvisionerJobError{ | ||
| message: job.Error, | ||
| code: job.ErrorCode, | ||
| } | ||
| jobMutex.Unlock() | ||
| flushLogBuffer() | ||
| return err | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,7 +6,6 @@ import ( | ||
| "fmt" | ||
| "io" | ||
| "reflect" | ||
| "sync" | ||
| "time" | ||
| @@ -30,11 +29,10 @@ import ( | ||
| "github.com/coder/retry" | ||
| ) | ||
| // IsMissingParameterError returns whether the error is a missing parameter error. | ||
| // This can indicate to consumers that they should check parameters. | ||
| func IsMissingParameterError(errorCode string) bool { | ||
mtojek marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return errorCode == runner.MissingParameterErrorCode | ||
| } | ||
| // Dialer represents the function to create a daemon client connection. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,8 +30,11 @@ import ( | ||
| ) | ||
| const ( | ||
| MissingParameterErrorCode = "MISSING_TEMPLATE_PARAMETER" | ||
| missingParameterErrorText = "missing parameter" | ||
| RequiredTemplateVariablesErrorCode = "REQUIRED_TEMPLATE_VARIABLES" | ||
| requiredTemplateVariablesErrorText = "required template variables" | ||
| ) | ||
| var errUpdateSkipped = xerrors.New("update skipped; job complete or failed") | ||
| @@ -590,8 +593,7 @@ func (r *Runner) runTemplateImport(ctx context.Context) (*proto.CompletedJob, *p | ||
| for _, parameterSchema := range parameterSchemas { | ||
| _, ok := valueByName[parameterSchema.Name] | ||
| if !ok { | ||
| return nil, r.failedJobf("%s: %s", missingParameterErrorText, parameterSchema.Name) | ||
| } | ||
| } | ||
| @@ -1053,16 +1055,17 @@ func (r *Runner) runWorkspaceBuild(ctx context.Context) (*proto.CompletedJob, *p | ||
| } | ||
| 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 | ||
| } | ||
Member 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? varerrorCodes=map[string]string{MissingParameterErrorCode:missingParameterErrorText,// ...}forc,m:=rangeerrorCodes {// ...} 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 MemberAuthor 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, | ||
| Error:message, | ||
| ErrorCode: code, | ||
| } | ||
| } | ||