diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-25 15:22:08 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-25 15:22:08 -0500 |
commit | c6dee2a05ab5e4f069ba443f030ef9d6c6d49db5 (patch) | |
tree | 69fb6f7e8824ae07b29e7337532cd0816ef4cfd4 /src | |
parent | e631a72b927711b502a429990fcbb2417e150c50 (diff) | |
download | nbsh-c6dee2a05ab5e4f069ba443f030ef9d6c6d49db5.tar.gz nbsh-c6dee2a05ab5e4f069ba443f030ef9d6c6d49db5.zip |
don't crash if we can't run a program
Diffstat (limited to 'src')
-rw-r--r-- | src/state/history.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/state/history.rs b/src/state/history.rs index 2b97e93..5a3b9ab 100644 --- a/src/state/history.rs +++ b/src/state/history.rs @@ -1,6 +1,7 @@ use async_std::io::{ReadExt as _, WriteExt as _}; use futures_lite::future::FutureExt as _; use pty_process::Command as _; +use std::error::Error as _; use std::os::unix::process::ExitStatusExt as _; pub struct History { @@ -586,9 +587,23 @@ async fn run_exe( let mut process = async_std::process::Command::new(exe.exe()); process.args(exe.args()); let size = entry.lock_arc().await.vt.screen().size(); - let child = process - .spawn_pty(Some(&pty_process::Size::new(size.0, size.1))) - .unwrap(); + let child = + process.spawn_pty(Some(&pty_process::Size::new(size.0, size.1))); + let child = match child { + Ok(child) => child, + Err(e) => { + let mut entry = entry.lock_arc().await; + entry.vt.process( + format!( + "\x1b[31mnbsh: failed to run {}: {}", + exe.exe(), + e.source().unwrap() + ) + .as_bytes(), + ); + return async_std::process::ExitStatus::from_raw(1 << 8); + } + }; loop { enum Res { Read(Result<usize, std::io::Error>), |