Skip to content

Preflight specific exit codes#732

Merged
matthewborden merged 7 commits intomainfrom
preflight-exit-codes
Mar 31, 2026
Merged

Preflight specific exit codes#732
matthewborden merged 7 commits intomainfrom
preflight-exit-codes

Conversation

@matthewborden
Copy link
Copy Markdown
Contributor

This introduces specific exit codes for preflight builds. This only currently considers the build state, it doesn't use failed jobs to determine the exit status yet, since preflight isn't currently aware of retries and wouldn't go from failure back to success, when a retry succeed. This uses the failing state, as a proxy for calculating retried jobs. We can enrich exit code 10 with failed jobs or tests.

Result.Error() maps preflight outcomes onto dedicated error categories and internal/errors/handler.go assigns stable exit codes for each one:

build.State Exit code Meaning
passed 0 Successful preflight
failed 9 Terminal preflight failure
canceled 9 Terminal preflight failure
skipped 9 Terminal preflight failure
not_run 9 Terminal preflight failure
failing 10 Active preflight failure
scheduled 11 Incomplete preflight
running 11 Incomplete preflight
blocked 11 Incomplete preflight
canceling 11 Incomplete preflight
any other state 12 Unknown preflight result

Control-C during the watch loop exits with exit code 128 using the existing ExitCodeUserAbortedError.

@matthewborden matthewborden requested review from a team as code owners March 30, 2026 05:12
Comment thread cmd/preflight/result_test.go
Comment thread cmd/preflight/render.go
Comment thread internal/errors/errors.go
Comment thread cmd/preflight/result.go
@matthewborden matthewborden force-pushed the preflight-exit-codes branch 4 times, most recently from 4867968 to 3d12860 Compare March 30, 2026 06:53
Comment thread cmd/preflight/render.go Outdated
Comment thread cmd/preflight/result.go
matthewborden and others added 6 commits March 31, 2026 14:32
This introduces `cmd/preflight.Result` to classify the final preflight `build.State` and return typed CLI errors instead of a generic `fmt.Errorf` for every non-passing result.

Previously `bk preflight` ended by returning plain string errors such as `preflight build failed`. `internal/errors/handler.go` treated those the same as any other generic failure, so scripts could not distinguish a completed failed build from an active failure, an incomplete build, or an unknown result.

With this change, `Result.Error()` maps preflight outcomes onto dedicated error categories and `internal/errors/handler.go` assigns stable exit codes for each one:

| `build.State` | Exit code | Meaning |
| --- | ---: | --- |
| `passed` | `0` | Successful preflight |
| `failed` | `9` | Terminal preflight failure |
| `canceled` | `9` | Terminal preflight failure |
| `skipped` | `9` | Terminal preflight failure |
| `not_run` | `9` | Terminal preflight failure |
| `failing` | `10` | Active preflight failure |
| `scheduled` | `11` | Incomplete preflight |
| `running` | `11` | Incomplete preflight |
| `blocked` | `11` | Incomplete preflight |
| `canceling` | `11` | Incomplete preflight |
| any other state | `12` | Unknown preflight result |

This keeps `bk preflight` on the shared CLI error-handling path while giving preflight-specific prefixes, messages, and automation-friendly exit codes.

Amp-Thread-ID: https://ampcode.com/threads/T-019d3d79-37bd-700b-8052-34e00ab1e618
Co-authored-by: Amp <amp@ampcode.com>
To seperate cleanup from results
@matthewborden matthewborden enabled auto-merge (squash) March 31, 2026 03:43
@matthewborden matthewborden merged commit 08b8020 into main Mar 31, 2026
1 check passed
@matthewborden matthewborden deleted the preflight-exit-codes branch March 31, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants