Skip to content

smitebot: return Result from command handlers - #280

Draft
Ashish-Kumar-Dash wants to merge 3 commits into
lnfuzz:masterfrom
Ashish-Kumar-Dash:smitebot-command-result-errors
Draft

Ashish-Kumar-Dash wants to merge 3 commits into
lnfuzz:masterfrom
Ashish-Kumar-Dash:smitebot-command-result-errors

Conversation

@Ashish-Kumar-Dash

Copy link
Copy Markdown
Contributor

Closes #270.

Command handlers logged the error and returned false. Now they return Result<(), CliError> and main logs once at the top, so bodies use ? and logging lives in one place.

New src/error.rs:

  • Config/State — #[from] the existing ConfigError/StateError.
  • Msg(String) — ready-to-log operational message (From<String> lets the bench-exec validators flow through ?).
  • Reported — the config/doctor report commands print their own output (incl. --json); main sets 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 only log::error! outside main.

…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.
@Ashish-Kumar-Dash Ashish-Kumar-Dash changed the title Smitebot command result errors smitebot: return Result from command handlers Oct 5, 2026
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.

smitebot: refactor to use Result<(), Error>

1 participant