From c47f4a56cda1c16ef4f48100e000e8d6e2581c4b Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Thu, 9 Sep 2021 08:50:33 -0400 Subject: [PATCH] check_cmd: Actually check the subcommand exit code. --- lib/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 24bfea0..0996093 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -8,10 +8,9 @@ pub mod ssh; pub mod terraform; pub mod types; -use anyhow::Result; use error::Error; -use anyhow::Context; +use anyhow::{anyhow, Context, Result}; use execute::Execute; use log::debug; use std::env; @@ -67,9 +66,16 @@ pub fn sh(command: std::process::Command) -> Result { fn check_cmd(cmd: &mut Command) -> Result<()> { println!("run: {:?}", cmd); - cmd.status()?; - - Ok(()) + let status = cmd.status()?; + if status.success() { + Ok(()) + } else { + Err(anyhow!( + "{:?} failed with non-zero exit code {:?}", + cmd, + status + )) + } } #[derive(Clone)]