Merge pull request #184 from nix-community/improve-subprocess-errors

tool: improve command error messages
This commit is contained in:
nikstur 2023-05-24 00:44:36 +02:00 committed by GitHub
commit 1f542a1eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -71,7 +71,7 @@ fn wrap_in_pe(stub: &Path, sections: Vec<Section>, 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 `{:?}`",

View File

@ -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() {

View File

@ -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<bool> {
.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())