various: nicer error handling

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib6f474603196a32df6e9745e74d0744f6a6a6964
This commit is contained in:
raf 2025-11-13 01:12:58 +03:00
commit 2739462ec0
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 27 additions and 29 deletions

View file

@ -70,10 +70,9 @@ impl NixFileFixer for DefaultNixFileFixer {
.collect(); .collect();
if files.is_empty() { if files.is_empty() {
Err(EhError::NoNixFilesFound) return Err(EhError::NoNixFilesFound);
} else {
Ok(files)
} }
Ok(files)
} }
fn fix_hash_in_file(&self, file_path: &Path, new_hash: &str) -> Result<bool> { fn fix_hash_in_file(&self, file_path: &Path, new_hash: &str) -> Result<bool> {
@ -275,7 +274,9 @@ pub fn handle_nix_with_retry(
} }
// Otherwise, show the error and return error // 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 { Err(EhError::ProcessExit {
code: output.status.code().unwrap_or(1), code: output.status.code().unwrap_or(1),
}) })

View file

@ -97,33 +97,30 @@ fn create_multicall_binaries(
fs::remove_file(&target_path)?; fs::remove_file(&target_path)?;
} }
match fs::hard_link(main_binary, &target_path) { if let Err(e) = fs::hard_link(main_binary, &target_path) {
Ok(()) => { eprintln!(
println!( " warning: could not create hardlink for {}: {e}",
" created hardlink: {} points to {}", binary.name(),
target_path.display(), );
main_binary.display(), 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)?; println!(" created copy: {}", target_path.display());
} else {
#[cfg(unix)] println!(
{ " created hardlink: {} points to {}",
use std::os::unix::fs::PermissionsExt; target_path.display(),
let mut perms = fs::metadata(&target_path)?.permissions(); main_binary.display(),
perms.set_mode(perms.mode() | 0o755); );
fs::set_permissions(&target_path, perms)?;
}
println!(" created copy: {}", target_path.display());
}
} }
} }