From f4de796293ad49202b8a9f8365db019e0e99a225 Mon Sep 17 00:00:00 2001 From: Jihyun Yu Date: Thu, 20 Mar 2025 10:22:06 +0000 Subject: [PATCH] Improve error reporting for missing commands Previously, installation failures would only display a generic 'Failure during installation' message, making troubleshooting difficult, especially for common issues like missing command-line tools. This update adds explicit error messages when required commands are not found, simplifying user troubleshooting. --- install/uvm_install_core/src/lib.rs | 7 +++++++ install/uvm_install_core/src/sys/linux/pkg.rs | 12 ++++++++---- install/uvm_install_core/src/sys/linux/xz.rs | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/install/uvm_install_core/src/lib.rs b/install/uvm_install_core/src/lib.rs index e572bd42..bd2d8d95 100644 --- a/install/uvm_install_core/src/lib.rs +++ b/install/uvm_install_core/src/lib.rs @@ -59,3 +59,10 @@ pub trait InstallHandler { Ok(()) } } + +pub fn handle_notfound(program: &str, e: std::io::Error) -> Error { + if let std::io::ErrorKind::NotFound = e.kind() { + error!("Error: '{0}' command not found.\nuvm requires '{0}' to install modules. Please ensure '{0}' is installed and accessible in your PATH.", program); + } + e.into() +} diff --git a/install/uvm_install_core/src/sys/linux/pkg.rs b/install/uvm_install_core/src/sys/linux/pkg.rs index 4b9a6bb8..74aed50f 100644 --- a/install/uvm_install_core/src/sys/linux/pkg.rs +++ b/install/uvm_install_core/src/sys/linux/pkg.rs @@ -30,7 +30,8 @@ impl ModulePkgInstaller { .arg(installer) .stdout(Stdio::piped()) .stderr(Stdio::piped()) - .spawn()?; + .spawn() + .map_err(|e| handle_notfound("7z", e))?; let output = child.wait_with_output()?; if !output.status.success() { @@ -59,7 +60,8 @@ impl ModulePkgInstaller { .arg("-iu") .current_dir(destination) .stdin(Stdio::piped()) - .spawn()?; + .spawn() + .map_err(|e| handle_notfound("cpio", e))?; { let stdin = cpio.stdin.as_mut().ok_or("Failed to open cpio stdin")?; let mut file = File::open(payload)?; @@ -72,13 +74,15 @@ impl ModulePkgInstaller { .arg("-dc") .arg(payload) .stdout(Stdio::piped()) - .spawn()?; + .spawn() + .map_err(|e| handle_notfound("gzip", e))?; let mut cpio = Command::new("cpio") .arg("-iu") .current_dir(destination) .stdin(Stdio::piped()) - .spawn()?; + .spawn() + .map_err(|e| handle_notfound("cpio", e))?; { let gzip_stdout = gzip.stdout.as_mut().ok_or("Failed to open gzip stdout")?; let cpio_stdin = cpio.stdin.as_mut().ok_or("Failed to open cpio stdin")?; diff --git a/install/uvm_install_core/src/sys/linux/xz.rs b/install/uvm_install_core/src/sys/linux/xz.rs index 34394d4c..6ea37efe 100644 --- a/install/uvm_install_core/src/sys/linux/xz.rs +++ b/install/uvm_install_core/src/sys/linux/xz.rs @@ -26,7 +26,8 @@ impl Installer { .stdin(Stdio::null()) .stdout(Stdio::null()) .stderr(Stdio::null()) - .spawn()?; + .spawn() + .map_err(|e| handle_notfound("tar", e))?; let tar_output = tar_child.wait_with_output()?; if !tar_output.status.success() {