From 30ddfcd2ceda86a952cbfae3cf99e7ce0796db4d Mon Sep 17 00:00:00 2001 From: nikstur Date: Wed, 24 May 2023 00:17:11 +0200 Subject: [PATCH] tool: improve command error messages --- rust/tool/src/pe.rs | 2 +- rust/tool/src/signature.rs | 13 ++++++++----- rust/tool/tests/common/mod.rs | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/rust/tool/src/pe.rs b/rust/tool/src/pe.rs index f0fc7ba..2a8ebb2 100644 --- a/rust/tool/src/pe.rs +++ b/rust/tool/src/pe.rs @@ -71,7 +71,7 @@ fn wrap_in_pe(stub: &Path, sections: Vec
, output: &Path) -> Result<()> let status = Command::new("objcopy") .args(&args) .status() - .context("Failed to run objcopy command")?; + .context("Failed to run objcopy. Most likely, the binary is not on PATH.")?; if !status.success() { return Err(anyhow::anyhow!( "Failed to wrap in pe with args `{:?}`", diff --git a/rust/tool/src/signature.rs b/rust/tool/src/signature.rs index badeebd..b78dfba 100644 --- a/rust/tool/src/signature.rs +++ b/rust/tool/src/signature.rs @@ -29,7 +29,10 @@ impl KeyPair { to.as_os_str().to_owned(), ]; - let output = Command::new("sbsign").args(&args).output()?; + let output = Command::new("sbsign") + .args(&args) + .output() + .context("Failed to run sbsign. Most likely, the binary is not on PATH.")?; if !output.status.success() { std::io::stderr() @@ -50,10 +53,10 @@ impl KeyPair { path.as_os_str().to_owned(), ]; - let output = match Command::new("sbverify").args(&args).output() { - Ok(output) => output, - Err(_) => return false, - }; + let output = Command::new("sbverify") + .args(&args) + .output() + .expect("Failed to run sbverify. Most likely, the binary is not on PATH."); if !output.status.success() { if std::io::stderr().write_all(&output.stderr).is_err() { diff --git a/rust/tool/tests/common/mod.rs b/rust/tool/tests/common/mod.rs index e650a79..2a9ea2e 100644 --- a/rust/tool/tests/common/mod.rs +++ b/rust/tool/tests/common/mod.rs @@ -182,7 +182,8 @@ pub fn remove_signature(path: &Path) -> Result<()> { let output = Command::new("sbattach") .arg("--remove") .arg(path.as_os_str()) - .output()?; + .output() + .context("Failed to run sbattach. Most likely, the binary is not on PATH.")?; print!("{}", String::from_utf8(output.stdout)?); print!("{}", String::from_utf8(output.stderr)?); Ok(()) @@ -194,7 +195,8 @@ pub fn verify_signature(path: &Path) -> Result { .arg(path.as_os_str()) .arg("--cert") .arg("tests/fixtures/uefi-keys/db.pem") - .output()?; + .output() + .context("Failed to run sbverify. Most likely, the binary is not on PATH.")?; print!("{}", String::from_utf8(output.stdout)?); print!("{}", String::from_utf8(output.stderr)?); Ok(output.status.success())