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,15 +97,7 @@ 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(()) => {
println!(
" created hardlink: {} points to {}",
target_path.display(),
main_binary.display(),
);
}
Err(e) => {
eprintln!( eprintln!(
" warning: could not create hardlink for {}: {e}", " warning: could not create hardlink for {}: {e}",
binary.name(), binary.name(),
@ -123,7 +115,12 @@ fn create_multicall_binaries(
} }
println!(" created copy: {}", target_path.display()); println!(" created copy: {}", target_path.display());
} } else {
println!(
" created hardlink: {} points to {}",
target_path.display(),
main_binary.display(),
);
} }
} }