Repository navigation
smitebot: return Result from command handlers - #280
Draft
Ashish-Kumar-Dash wants to merge 3 commits into
Draft
Ashish-Kumar-Dash wants to merge 3 commits into
Ashish-Kumar-Dash wants to merge 3 commits into
Conversation
…d_campaign stop, status, and reproduce each repeated the same 18-line block: resolve runs_dir, build the state path, load state, and log a not-found hint on failure. Extract it into CampaignState::load_campaign(id) -> Option<(Self, PathBuf)>, collapsing each call site to one line.
Command handlers logged the error and returned false on failure, which is non-idiomatic and verbose. Return the error instead and log it once in main, so the command bodies can use `?` and logging lives in one place (issue lnfuzz#270). Add CliError in src/error.rs: Config/State wrap the existing module errors via #[from], Msg carries a ready-to-log operational message, and Reported marks the config/doctor report commands whose printed output (including JSON) is the artifact — main sets the exit code but logs nothing further so the output is not duplicated. From<String> lets the bench-exec validators flow through `?`. Functions whose bool/Option is a genuine domain verdict rather than an error channel stay as they are: verify_startup (per-runner diagnostics), stop's reap helpers (clean vs survivors), and the pure predicates. Net -132 lines.
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.
Closes #270.
Command handlers logged the error and returned
false. Now they returnResult<(), CliError>andmainlogs once at the top, so bodies use?and logging lives in one place.New
src/error.rs:Config/State—#[from]the existingConfigError/StateError.Msg(String)— ready-to-log operational message (From<String>lets the bench-exec validators flow through?).Reported— theconfig/doctorreport commands print their own output (incl.--json);mainsets the exit code but logs nothing further.Left as
bool/Option(genuine verdicts, not error channels):verify_startup(per-runner diagnostics),stop's reap helpers (clean vs survivors), pure predicates. Those hold the onlylog::error!outsidemain.