Skip to main content

finish_batch

Function finish_batch 

Source
pub fn finish_batch(
    failed: usize,
    total: usize,
    op: &'static str,
) -> SshCliResult<()>
Expand description

Turns a multi-host fan-out tally into the batch outcome.

Single source for the “N of M failed” verdict. The same eight-line block used to be copy-pasted across the SCP, SFTP, exec and health-check batch paths, each one building a SshCliError::Config (exit 65) by hand — so a partial fan-out was indistinguishable from corrupt TOML. Callers now report the tally and let this decide.

total must count every target the caller was asked to reach, including ones skipped by --fail-fast; otherwise the ratio understates the work not done.

§Errors

SshCliError::PartialFailure when failed > 0.

§Examples

use ssh_cli::errors::{finish_batch, SshCliError};

assert!(finish_batch(0, 10, "exec").is_ok());

let err = finish_batch(3, 10, "exec").unwrap_err();
assert_eq!(err.exit_code(), ssh_cli::errors::exit_codes::EX_GENERAL);
assert_eq!(err.error_code(), "partial_failure");
assert!(matches!(err, SshCliError::PartialFailure { failed: 3, total: 10, .. }));