summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRory Dudley2024-02-19 02:33:36 -0700
committerRory Dudley2024-02-19 02:33:36 -0700
commit08be85a2fc508450c6361af4ef38a7dcd3efbde5 (patch)
tree3d57a1940200f93b49e506b4e435af0d5a40d3e9
parent2e5cc53499947c32b01ea5e1787ed505bc286969 (diff)
downloaddwarvish-08be85a2fc508450c6361af4ef38a7dcd3efbde5.tar.gz
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.
-rw-r--r--src/main.rs15
1 files changed, 12 insertions, 3 deletions
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;
}
};