From 28953168e80183fe11d2031369b48022eefd37e5 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 8 Jan 2022 19:39:22 -0500 Subject: remove a bunch of unwraps --- src/shell/history/mod.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/shell') diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index 909a6e8..2f84c37 100644 --- a/src/shell/history/mod.rs +++ b/src/shell/history/mod.rs @@ -488,13 +488,11 @@ async fn run_pipeline( env: &mut Env, event_w: async_std::channel::Sender, ) -> anyhow::Result<(async_std::process::ExitStatus, bool)> { - let mut cmd = pty_process::Command::new(std::env::current_exe().unwrap()); + let mut cmd = pty_process::Command::new(std::env::current_exe()?); cmd.arg("--internal-cmd-runner"); env.apply(&mut cmd); - let (to_r, to_w) = - nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC).unwrap(); - let (from_r, from_w) = - nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC).unwrap(); + let (to_r, to_w) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?; + let (from_r, from_w) = nix::unistd::pipe2(nix::fcntl::OFlag::O_CLOEXEC)?; // Safety: dup2 is an async-signal-safe function unsafe { cmd.pre_exec(move || { @@ -503,17 +501,15 @@ async fn run_pipeline( Ok(()) }); } - let child = pty.spawn(cmd).unwrap(); - nix::unistd::close(to_r).unwrap(); - nix::unistd::close(from_w).unwrap(); + let child = pty.spawn(cmd)?; + nix::unistd::close(to_r)?; + nix::unistd::close(from_w)?; // Safety: to_w was just opened above, was not used until now, and can't // be used after this because we rebound the variable let mut to_w = unsafe { async_std::fs::File::from_raw_fd(to_w) }; - to_w.write_all(&bincode::serialize(pipeline).unwrap()) - .await - .unwrap(); - to_w.write_all(&env.as_bytes()).await.unwrap(); + to_w.write_all(&bincode::serialize(pipeline)?).await?; + to_w.write_all(&env.as_bytes()).await?; drop(to_w); let (read_w, read_r) = async_std::channel::unbounded(); @@ -581,7 +577,7 @@ async fn run_pipeline( } } if let (true, Some(status)) = (read_done, exit_done) { - nix::unistd::close(from_r).unwrap(); + nix::unistd::close(from_r)?; // nix::sys::signal::Signal is repr(i32) #[allow(clippy::as_conversions)] return Ok(( -- cgit v1.2.3-54-g00ecf