summaryrefslogtreecommitdiffstats
path: root/src/state/history/mod.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-04 21:50:11 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-04 21:50:11 -0500
commiteba8f5bbc0c27bc9eee3da078631e5248c5ae01f (patch)
treef7156f9d17eba65a16861cfac5aa5680c32d8f89 /src/state/history/mod.rs
parent7dc66c5b6e3e607b9fd6af4d19e2bbc93d573282 (diff)
downloadnbsh-eba8f5bbc0c27bc9eee3da078631e5248c5ae01f.tar.gz
nbsh-eba8f5bbc0c27bc9eee3da078631e5248c5ae01f.zip
fix error handling in pipeline runner
eprintln is not a useful thing to do here
Diffstat (limited to 'src/state/history/mod.rs')
-rw-r--r--src/state/history/mod.rs37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs
index 673b39c..9f2d254 100644
--- a/src/state/history/mod.rs
+++ b/src/state/history/mod.rs
@@ -572,7 +572,8 @@ fn run_commands(
Err(e) => {
let mut entry = entry.lock_arc().await;
entry.vt.process(
- format!("nbsh: failed to allocate pty: {}", e).as_bytes(),
+ format!("nbsh: failed to allocate pty: {}\r\n", e)
+ .as_bytes(),
);
env.set_status(async_std::process::ExitStatus::from_raw(
1 << 8,
@@ -584,11 +585,23 @@ fn run_commands(
for pipeline in ast.pipelines() {
env.set_pipeline(pipeline.input_string().to_string());
- let (pipeline_status, done) =
- run_pipeline(&pty, &mut env, event_w.clone()).await;
- env.set_status(pipeline_status);
- if done {
- break;
+ match run_pipeline(&pty, &mut env, event_w.clone()).await {
+ Ok((pipeline_status, done)) => {
+ env.set_status(pipeline_status);
+ if done {
+ break;
+ }
+ }
+ Err(e) => {
+ entry
+ .lock_arc()
+ .await
+ .vt
+ .process(format!("nbsh: {}\r\n", e).as_bytes());
+ env.set_status(async_std::process::ExitStatus::from_raw(
+ 1 << 8,
+ ));
+ }
}
}
entry.lock_arc().await.finish(env, event_w).await;
@@ -601,7 +614,7 @@ async fn run_pipeline(
pty: &pty::Pty,
env: &mut crate::env::Env,
event_w: async_std::channel::Sender<crate::event::Event>,
-) -> (async_std::process::ExitStatus, bool) {
+) -> anyhow::Result<(async_std::process::ExitStatus, bool)> {
let mut cmd = pty_process::Command::new(std::env::current_exe().unwrap());
cmd.arg("--internal-cmd-runner");
env.apply(&mut cmd);
@@ -656,13 +669,12 @@ async fn run_pipeline(
continue;
}
}
- eprintln!("nbsh: {}", e);
- return (std::process::ExitStatus::from_raw(1 << 8), false);
+ anyhow::bail!(e);
}
Res::Exit(Ok(status)) => {
// nix::sys::signal::Signal is repr(i32)
#[allow(clippy::as_conversions)]
- return (
+ return Ok((
status,
// i'm not sure what exactly the expected behavior here is
// - in zsh, SIGINT kills the whole command line while
@@ -670,11 +682,10 @@ async fn run_pipeline(
// logic is or how other signals are handled
status.signal()
== Some(nix::sys::signal::Signal::SIGINT as i32),
- );
+ ));
}
Res::Exit(Err(e)) => {
- eprintln!("nbsh: {}", e);
- return (std::process::ExitStatus::from_raw(1 << 8), false);
+ anyhow::bail!(e);
}
}
}