diff --git a/crates/common/tedge_config/src/sudo.rs b/crates/common/tedge_config/src/sudo.rs index 61b7d1da43c..9c3cd38b1dd 100644 --- a/crates/common/tedge_config/src/sudo.rs +++ b/crates/common/tedge_config/src/sudo.rs @@ -57,7 +57,7 @@ impl SudoCommandBuilder { c } Err(_) => { - warn!("`sudo.enable` set to `true`, but sudo not found in $PATH"); + warn!("`sudo.enable` set to `true`, but sudo not found in $PATH, using tedge-write directly"); Command::new(program) } } diff --git a/crates/core/tedge_write/src/api.rs b/crates/core/tedge_write/src/api.rs index bc235a3a17b..ca9bd09b0e6 100644 --- a/crates/core/tedge_write/src/api.rs +++ b/crates/core/tedge_write/src/api.rs @@ -33,24 +33,30 @@ impl<'a> CopyOptions<'a> { /// /// Stdin and Stdout are UTF-8. pub fn copy(self) -> anyhow::Result<()> { - let output = self - .command()? - .output() - .context("Starting tedge-write process failed")?; + let mut command = self.command()?; + + let output = command.output(); + + let program = command.get_program().to_string_lossy(); + let output = output.with_context(|| format!("failed to start process '{program}'"))?; if !output.status.success() { + let stderr = String::from_utf8(output.stderr).expect("output should be utf-8"); + let stderr = stderr.trim(); + let exit_code = output.status.code().unwrap(); return Err(anyhow!( - String::from_utf8(output.stderr).expect("output should be utf-8") + "process returned non-zero exit code ({exit_code}); stderr=\"{stderr}\"" )); } Ok(()) } - fn command(&self) -> std::io::Result { + fn command(&self) -> anyhow::Result { let mut command = self.sudo.command(crate::TEDGE_WRITE_PATH); - let from_reader = std::fs::File::open(self.from)?; + let from_reader = std::fs::File::open(self.from) + .with_context(|| format!("could not open file for reading '{}'", self.from))?; command.stdin(from_reader).arg(self.to); if let Some(mode) = self.mode { diff --git a/crates/extensions/tedge_config_manager/src/error.rs b/crates/extensions/tedge_config_manager/src/error.rs index 94af86faf16..57465302a39 100644 --- a/crates/extensions/tedge_config_manager/src/error.rs +++ b/crates/extensions/tedge_config_manager/src/error.rs @@ -35,7 +35,7 @@ pub enum ConfigManagementError { #[error(transparent)] FromAtomFileError(#[from] tedge_utils::fs::AtomFileError), - #[error(transparent)] + #[error("{0:#}")] Other(#[from] anyhow::Error), }