Skip to content

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

Merged
merged 9 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add errors to typesGenerated
  • Loading branch information
mtojek committed Mar 8, 2023
commit ee381ab868c0da32ecb7f9058ad94103d60e1b53
4 changes: 2 additions & 2 deletions cli/cliui/provisionerjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ProvisionerJobOptions struct {

type ProvisionerJobError struct {
message string
code string
code codersdk.JobErrorCode
}

var _ error = new(ProvisionerJobError)
Expand All @@ -52,7 +52,7 @@ func (err *ProvisionerJobError) Error() string {
return err.message
}

func (err *ProvisionerJobError) Code() string {
func (err *ProvisionerJobError) Code() codersdk.JobErrorCode {
return err.code
}

Expand Down
4 changes: 2 additions & 2 deletions cli/templatecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
})
if err != nil {
var jobErr *cliui.ProvisionerJobError
if errors.As(err, &jobErr) && !provisionerd.IsMissingParameterError(jobErr.Code()) {
if errors.As(err, &jobErr) && !provisionerd.IsMissingParameterError(string(jobErr.Code())) {
return nil, nil, err
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func createValidTemplateVersion(cmd *cobra.Command, args createValidTemplateVers
}
}

if provisionerd.IsMissingParameterError(version.Job.ErrorCode) {
if provisionerd.IsMissingParameterError(string(version.Job.ErrorCode)) {
valuesBySchemaID := map[string]codersdk.ComputedParameter{}
for _, parameterValue := range parameterValues {
valuesBySchemaID[parameterValue.SchemaID.String()] = parameterValue
Expand Down
21 changes: 20 additions & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func convertProvisionerJob(provisionerJob database.ProvisionerJob) codersdk.Prov
ID: provisionerJob.ID,
CreatedAt: provisionerJob.CreatedAt,
Error: provisionerJob.Error.String,
ErrorCode: provisionerJob.ErrorCode.String,
ErrorCode: codersdk.JobErrorCode(provisionerJob.ErrorCode.String),
FileID: provisionerJob.FileID,
Tags: provisionerJob.Tags,
}
Expand Down
10 changes: 9 additions & 1 deletion codersdk/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -75,7 +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 string `json:"error_code,omitempty"`
ErrorCode JobErrorCode `json:"error_code,omitempty" enums:"MISSING_TEMPLATE_PARAMETER,REQUIRED_TEMPLATE_VARIABLES"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is the enums: still required for code gen even after the update of swaggo? In my experience it has been able to auto-detect but it might be very specific.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 swagger.json, so I will leave it as is.

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"`
Expand Down
108 changes: 55 additions & 53 deletions docs/api/builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -189,7 +189,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild} \
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -714,7 +714,7 @@ curl -X GET http://coder-server:8080/api/v2/workspacebuilds/{workspacebuild}/sta
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -869,7 +869,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace}/builds \
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -1000,7 +1000,7 @@ Status Code **200**
| `»» completed_at` | string(date-time) | false | | |
| `»» created_at` | string(date-time) | false | | |
| `»» error` | string | false | | |
| `»» error_code` | string | false | | |
| `»» error_code` | [codersdk.JobErrorCode](schemas.md#codersdkjoberrorcode) | false | | |
| `»» file_id` | string(uuid) | false | | |
| `»» id` | string(uuid) | false | | |
| `»» started_at` | string(date-time) | false | | |
Expand Down Expand Up @@ -1081,53 +1081,55 @@ Status Code **200**

#### Enumerated Values

| Property | Value |
| ---------------------- | ------------------ |
| `status` | `pending` |
| `status` | `running` |
| `status` | `succeeded` |
| `status` | `canceling` |
| `status` | `canceled` |
| `status` | `failed` |
| `reason` | `initiator` |
| `reason` | `autostart` |
| `reason` | `autostop` |
| `health` | `disabled` |
| `health` | `initializing` |
| `health` | `healthy` |
| `health` | `unhealthy` |
| `sharing_level` | `owner` |
| `sharing_level` | `authenticated` |
| `sharing_level` | `public` |
| `lifecycle_state` | `created` |
| `lifecycle_state` | `starting` |
| `lifecycle_state` | `start_timeout` |
| `lifecycle_state` | `start_error` |
| `lifecycle_state` | `ready` |
| `lifecycle_state` | `shutting_down` |
| `lifecycle_state` | `shutdown_timeout` |
| `lifecycle_state` | `shutdown_error` |
| `lifecycle_state` | `off` |
| `status` | `connecting` |
| `status` | `connected` |
| `status` | `disconnected` |
| `status` | `timeout` |
| `workspace_transition` | `start` |
| `workspace_transition` | `stop` |
| `workspace_transition` | `delete` |
| `status` | `pending` |
| `status` | `starting` |
| `status` | `running` |
| `status` | `stopping` |
| `status` | `stopped` |
| `status` | `failed` |
| `status` | `canceling` |
| `status` | `canceled` |
| `status` | `deleting` |
| `status` | `deleted` |
| `transition` | `start` |
| `transition` | `stop` |
| `transition` | `delete` |
| Property | Value |
| ---------------------- | ----------------------------- |
| `error_code` | `MISSING_TEMPLATE_PARAMETER` |
| `error_code` | `REQUIRED_TEMPLATE_VARIABLES` |
| `status` | `pending` |
| `status` | `running` |
| `status` | `succeeded` |
| `status` | `canceling` |
| `status` | `canceled` |
| `status` | `failed` |
| `reason` | `initiator` |
| `reason` | `autostart` |
| `reason` | `autostop` |
| `health` | `disabled` |
| `health` | `initializing` |
| `health` | `healthy` |
| `health` | `unhealthy` |
| `sharing_level` | `owner` |
| `sharing_level` | `authenticated` |
| `sharing_level` | `public` |
| `lifecycle_state` | `created` |
| `lifecycle_state` | `starting` |
| `lifecycle_state` | `start_timeout` |
| `lifecycle_state` | `start_error` |
| `lifecycle_state` | `ready` |
| `lifecycle_state` | `shutting_down` |
| `lifecycle_state` | `shutdown_timeout` |
| `lifecycle_state` | `shutdown_error` |
| `lifecycle_state` | `off` |
| `status` | `connecting` |
| `status` | `connected` |
| `status` | `disconnected` |
| `status` | `timeout` |
| `workspace_transition` | `start` |
| `workspace_transition` | `stop` |
| `workspace_transition` | `delete` |
| `status` | `pending` |
| `status` | `starting` |
| `status` | `running` |
| `status` | `stopping` |
| `status` | `stopped` |
| `status` | `failed` |
| `status` | `canceling` |
| `status` | `canceled` |
| `status` | `deleting` |
| `status` | `deleted` |
| `transition` | `start` |
| `transition` | `stop` |
| `transition` | `delete` |

To perform this operation, you must be authenticated. [Learn more](authentication.md).

Expand Down Expand Up @@ -1197,7 +1199,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaces/{workspace}/builds \
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down
45 changes: 31 additions & 14 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,21 @@ CreateParameterRequest is a structure used to create a new parameter value for a
| `threshold` | integer | false | | Threshold specifies the number of consecutive failed health checks before returning "unhealthy". |
| `url` | string | false | | URL specifies the endpoint to check for the app health. |

## codersdk.JobErrorCode

```json
"MISSING_TEMPLATE_PARAMETER"
```

### Properties

#### Enumerated Values

| Value |
| ----------------------------- |
| `MISSING_TEMPLATE_PARAMETER` |
| `REQUIRED_TEMPLATE_VARIABLES` |

## codersdk.License

```json
Expand Down Expand Up @@ -3033,7 +3048,7 @@ Parameter represents a set value for the scope.
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand All @@ -3054,7 +3069,7 @@ Parameter represents a set value for the scope.
| `completed_at` | string | false | | |
| `created_at` | string | false | | |
| `error` | string | false | | |
| `error_code` | string | false | | |
| `error_code` | [codersdk.JobErrorCode](#codersdkjoberrorcode) | false | | |
| `file_id` | string | false | | |
| `id` | string | false | | |
| `started_at` | string | false | | |
Expand All @@ -3065,14 +3080,16 @@ Parameter represents a set value for the scope.

#### Enumerated Values

| Property | Value |
| -------- | ----------- |
| `status` | `pending` |
| `status` | `running` |
| `status` | `succeeded` |
| `status` | `canceling` |
| `status` | `canceled` |
| `status` | `failed` |
| Property | Value |
| ------------ | ----------------------------- |
| `error_code` | `MISSING_TEMPLATE_PARAMETER` |
| `error_code` | `REQUIRED_TEMPLATE_VARIABLES` |
| `status` | `pending` |
| `status` | `running` |
| `status` | `succeeded` |
| `status` | `canceling` |
| `status` | `canceled` |
| `status` | `failed` |

## codersdk.ProvisionerJobLog

Expand Down Expand Up @@ -3593,7 +3610,7 @@ Parameter represents a set value for the scope.
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -4092,7 +4109,7 @@ Parameter represents a set value for the scope.
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -4562,7 +4579,7 @@ Parameter represents a set value for the scope.
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down Expand Up @@ -4933,7 +4950,7 @@ Parameter represents a set value for the scope.
"completed_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"error": "string",
"error_code": "string",
"error_code": "MISSING_TEMPLATE_PARAMETER",
"file_id": "8a0cfb4f-ddc9-436d-91bb-75133c583767",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"started_at": "2019-08-24T14:15:22Z",
Expand Down
Loading