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:
Marcin Tojek
2023-03-08 16:32:00 +01:00
committed by GitHub
parent 524b14adbc
commit 3b87316ad7
25 changed files with 406 additions and 234 deletions

View File

@ -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

View File

@ -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