From 2739462ec029980c5bcfb2e745be9ba5e2db819f Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 13 Nov 2025 01:12:58 +0300 Subject: [PATCH] various: nicer error handling Signed-off-by: NotAShelf Change-Id: Ib6f474603196a32df6e9745e74d0744f6a6a6964 --- eh/src/util.rs | 9 +++++---- xtask/src/main.rs | 47 ++++++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/eh/src/util.rs b/eh/src/util.rs index 3ecdeec..9f93b55 100644 --- a/eh/src/util.rs +++ b/eh/src/util.rs @@ -70,10 +70,9 @@ impl NixFileFixer for DefaultNixFileFixer { .collect(); if files.is_empty() { - Err(EhError::NoNixFilesFound) - } else { - Ok(files) + return Err(EhError::NoNixFilesFound); } + Ok(files) } fn fix_hash_in_file(&self, file_path: &Path, new_hash: &str) -> Result { @@ -275,7 +274,9 @@ pub fn handle_nix_with_retry( } // Otherwise, show the error and return error - std::io::stderr().write_all(&output.stderr)?; + std::io::stderr() + .write_all(&output.stderr) + .map_err(EhError::Io)?; Err(EhError::ProcessExit { code: output.status.code().unwrap_or(1), }) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index b747f05..25a772c 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -97,33 +97,30 @@ fn create_multicall_binaries( fs::remove_file(&target_path)?; } - match fs::hard_link(main_binary, &target_path) { - Ok(()) => { - println!( - " created hardlink: {} points to {}", - target_path.display(), - main_binary.display(), - ); + if let Err(e) = fs::hard_link(main_binary, &target_path) { + eprintln!( + " warning: could not create hardlink for {}: {e}", + binary.name(), + ); + eprintln!(" warning: falling back to copying binary..."); + + fs::copy(main_binary, &target_path)?; + + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + let mut perms = fs::metadata(&target_path)?.permissions(); + perms.set_mode(perms.mode() | 0o755); + fs::set_permissions(&target_path, perms)?; } - Err(e) => { - eprintln!( - " warning: could not create hardlink for {}: {e}", - binary.name(), - ); - eprintln!(" warning: falling back to copying binary..."); - fs::copy(main_binary, &target_path)?; - - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - let mut perms = fs::metadata(&target_path)?.permissions(); - perms.set_mode(perms.mode() | 0o755); - fs::set_permissions(&target_path, perms)?; - } - - println!(" created copy: {}", target_path.display()); - } + println!(" created copy: {}", target_path.display()); + } else { + println!( + " created hardlink: {} points to {}", + target_path.display(), + main_binary.display(), + ); } }