From 599579eb044452f496d43efdb787b9af6fe3d7db Mon Sep 17 00:00:00 2001 From: Donal Byrne Date: Sun, 11 Aug 2024 11:36:35 +0200 Subject: [PATCH] Rework error code for delete --- src/executor.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/executor.rs b/src/executor.rs index 39e1b4c..298d75e 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -297,19 +297,19 @@ impl DefaultExecutor { let ids = ids.split("\n").collect::>(); - let mut failed = false; - for id in ids { + let failures: Vec<_> = ids.iter().filter_map(|id|{ match self.remove_pod(id, grace_period) { - Ok(_) => {} + Ok(_) => None, Err(e) => { - eprintln!("{}", e); - failed = true; + Some(e) } - }; - } + } + }).collect(); - if failed { - return Err(anyhow!("failures when removing pods for deployment").into()); + if !failures.is_empty() { + let mut err = anyhow!("failures when removing pods for deployment"); + err = failures.iter().fold(err, |a, b| a.context(b.to_string())); + return Err(err.into()); } Ok(()) } @@ -322,19 +322,19 @@ impl DefaultExecutor { let ids = ids.split("\n").collect::>(); - let mut failed = false; - for id in ids { + let failures: Vec<_> = ids.iter().filter_map(|id|{ match self.remove_pod(id, grace_period) { - Ok(_) => {} + Ok(_) => None, Err(e) => { - eprintln!("{}", e); - failed = true; + Some(e) } - }; - } + } + }).collect(); - if failed { - return Err(anyhow!("failures when removing pods for daemonset").into()); + if !failures.is_empty() { + let mut err = anyhow!("failures when removing pods for daemonset"); + err = failures.iter().fold(err, |a, b| a.context(b.to_string())); + return Err(err.into()); } Ok(()) }