From 08be85a2fc508450c6361af4ef38a7dcd3efbde5 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Mon, 19 Feb 2024 02:33:36 -0700 Subject: Better handling of errors during the fork Adds two additional error checks when the shell forks: 1. Checks for permission (+r, +x) 2. Checks if the file exists The first error may occur if the user does not have read access to the file, or if the file is not executable. The second error may occur if a file was removed from the $PATH, and the $PATH hasn't been refreshed yet. --- src/main.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 4d56375..c27bad7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,10 +108,19 @@ fn eval(paths: &[&str], prompt: &str) { } // Run the command (and wait for it to finish) - let mut child = match Command::new(cmd).args(args).spawn() { + let mut child = match Command::new(&cmd).args(args).spawn() { Ok(ch) => ch, - Err(_) => { - println!("Unable to fork"); + Err(err) => { + match err.kind() { + std::io::ErrorKind::PermissionDenied => println!( + "dwvsh: error: permission denied trying to fork to {}...", + &cmd + ), + // TODO: Refresh paths if error kind is NotFound + std::io::ErrorKind::NotFound => println!("dwvsh: error: command not found..."), + _ => println!("dwvsh: error: unable to fork..."), + } + continue; } }; -- cgit v1.2.3