From bf690423ea0f2537c51331722882af7515e21844 Mon Sep 17 00:00:00 2001 From: Patrik Keller Date: Mon, 15 Jan 2024 15:02:20 +0100 Subject: [PATCH] Set error code > 0 when colmena exec fails --- src/command/exec.rs | 21 +++++++++++++++++---- src/error.rs | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/command/exec.rs b/src/command/exec.rs index a2b8d38..5f3616a 100644 --- a/src/command/exec.rs +++ b/src/command/exec.rs @@ -110,9 +110,18 @@ pub async fn run( })); } - join_all(futures).await; + let results: Vec> = join_all(futures).await; - Ok(()) + let mut failed: usize = 0; + + for x in results { + match x { + Err(_) => failed += 1, + Ok(_) => (), + } + } + + Ok(failed) }); let (meta, monitor, output) = tokio::join!( @@ -121,9 +130,13 @@ pub async fn run( output.run_until_completion(), ); - meta?; + let failed = meta?; monitor?; output?; - Ok(()) + if failed > 0 { + Err(ColmenaError::ExecError { n_hosts: failed }) + } else { + Ok(()) + } } diff --git a/src/error.rs b/src/error.rs index 9b827ea..a9855e6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -75,6 +75,9 @@ pub enum ColmenaError { #[snafu(display("Unknown error: {}", message))] Unknown { message: String }, + + #[snafu(display("Exec failed on {} hosts", n_hosts))] + ExecError { n_hosts: usize }, } impl From for ColmenaError {