From 1fbd317b4a739c96accb27ff6ca4db2e5b7c7cfb Mon Sep 17 00:00:00 2001 From: Artturin Date: Sun, 20 Nov 2022 17:57:03 +0200 Subject: [PATCH] Show error and exit upon nix-locate failure Co-authored-by: gabriel-doriath-dohler --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f70be66..3a7456a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,12 +72,21 @@ fn main() -> ExitCode { index::check_database(); - let attrs = Command::new("nix-locate") + let nix_locate_output = Command::new("nix-locate") .args(["--top-level", "--minimal", "--at-root", "--whole-name"]) .arg(format!("/bin/{}", command)) .output() - .expect("failed to execute nix-locate") - .stdout; + .expect("failed to execute nix-locate"); + + if !nix_locate_output.status.success() { + match std::str::from_utf8(&nix_locate_output.stderr) { + Ok(stderr) => eprintln!("nix-locate failed with: {}", stderr), + Err(_) => eprint!("nix-locate failed"), + } + return ExitCode::FAILURE; + } + + let attrs = nix_locate_output.stdout; if attrs.is_empty() { eprintln!("No executable `{}` found in nix-index database.", command);