mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
feat: propagate job error codes (#6507)
* feat: propagate job error_code * fix * Fix * Fix * Fix * add errors to typesGenerated * Address PR comments * Fix
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -196,7 +197,8 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
if !provisionerd.IsMissingParameterError(err.Error()) {
|
||||
var jobErr *cliui.ProvisionerJobError
|
||||
if errors.As(err, &jobErr) && !provisionerd.IsMissingParameterErrorCode(string(jobErr.Code)) {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
@ -233,7 +235,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
|
||||
}
|
||||
}
|
||||
|
||||
if provisionerd.IsMissingParameterError(version.Job.Error) {
|
||||
if provisionerd.IsMissingParameterErrorCode(string(version.Job.ErrorCode)) {
|
||||
valuesBySchemaID := map[string]codersdk.ComputedParameter{}
|
||||
for _, parameterValue := range parameterValues {
|
||||
valuesBySchemaID[parameterValue.SchemaID.String()] = parameterValue
|
||||
|
Reference in New Issue
Block a user