refactor(hm-plugin-cloud): Replace raw i32 process exit codes with a typed ExitCode enum#115
Merged
markovejnovic merged 1 commit intoJun 10, 2026
Conversation
…typed ExitCode enum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The smell
dispatchanddispatch_commandincrates/hm-plugin-cloud/src/cli.rsreturnResult<i32>and write process exit codes as bare integer literals:Ok(0)(success),Ok(2)(arg-parse failure), andOk(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 singleFrom<ExitCode> for i32impl mapping the variants to0/1/2. The dispatch arms now produceExitCode::Success.into(),ExitCode::UsageError.into(), andExitCode::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 thefdrepository,sharkdp/fd,src/exit_codes.rs): the magic0/1/2appears exactly once, each code is self-documenting at every call site, and the exhaustivematchin theFromimpl prevents accidentally introducing an undefined status.Validation
Only
cargo check -p hm-plugin-cloudwas run locally (passes). Full CI runs on this PR. Draft because it still needs review.