Skip to content

refactor(hm-plugin-cloud): Replace raw i32 process exit codes with a typed ExitCode enum#115

Merged
markovejnovic merged 1 commit into
mainfrom
cq/hm-plugin-cloud-replace-raw-i32-process-exit-codes-with--17
Jun 10, 2026
Merged

refactor(hm-plugin-cloud): Replace raw i32 process exit codes with a typed ExitCode enum#115
markovejnovic merged 1 commit into
mainfrom
cq/hm-plugin-cloud-replace-raw-i32-process-exit-codes-with--17

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

The smell

dispatch and dispatch_command in crates/hm-plugin-cloud/src/cli.rs return Result<i32> and write process exit codes as bare integer literals: Ok(0) (success), Ok(2) (arg-parse failure), and Ok(1) (runtime error). The meaning of each number was implicit and the same magic values were duplicated across both functions, so a reader had to know the convention and a typo could silently return an undefined status.

The change

Introduces a small private enum ExitCode { Success, RuntimeError, UsageError } with a single From<ExitCode> for i32 impl mapping the variants to 0 / 1 / 2. The dispatch arms now produce ExitCode::Success.into(), ExitCode::UsageError.into(), and ExitCode::RuntimeError.into() instead of bare integers. The integer mapping is unchanged, so behavior is preserved.

Type-safety pattern

This applies fd's "typed exit code enum with From<ExitCode> for i32" pattern (see the fd repository, sharkdp/fd, src/exit_codes.rs): the magic 0/1/2 appears exactly once, each code is self-documenting at every call site, and the exhaustive match in the From impl prevents accidentally introducing an undefined status.

Validation

Only cargo check -p hm-plugin-cloud was run locally (passes). Full CI runs on this PR. Draft because it still needs review.

@markovejnovic markovejnovic marked this pull request as ready for review June 10, 2026 19:17
@markovejnovic markovejnovic merged commit b753567 into main Jun 10, 2026
17 checks passed
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.

1 participant