diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2022-10-28 14:43:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 14:43:06 +0000 |
commit | 6ae18b418724b16a04d04c5a480120b49a5ff595 (patch) | |
tree | f97a4ac33ddf32d7f03bd9219d2653be433bc994 /zellij-server | |
parent | f23108f63f83312c20504b4002727fd01dcec0a2 (diff) |
errors: Don't unwrap in `server::pty_writer` (#1872)
* server/pty_writer: Don't unwrap
and handle occuring errors instead. Replace calls to `log::error` with
`non_fatal` instead.
* server/pty_writer: Apply rustfmt
Diffstat (limited to 'zellij-server')
-rw-r--r-- | zellij-server/src/lib.rs | 2 | ||||
-rw-r--r-- | zellij-server/src/pty_writer.rs | 30 |
2 files changed, 20 insertions, 12 deletions
diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index c3a29ed13..147fe91fb 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -737,7 +737,7 @@ fn init_session( None, Some(os_input.clone()), ); - || pty_writer_main(pty_writer_bus) + || pty_writer_main(pty_writer_bus).fatal() }) .unwrap(); diff --git a/zellij-server/src/pty_writer.rs b/zellij-server/src/pty_writer.rs index 353849b58..f839b2427 100644 --- a/zellij-server/src/pty_writer.rs +++ b/zellij-server/src/pty_writer.rs @@ -1,4 +1,4 @@ -use zellij_utils::errors::{ContextType, PtyWriteContext}; +use zellij_utils::errors::{prelude::*, ContextType, PtyWriteContext}; use crate::thread_bus::Bus; @@ -17,22 +17,30 @@ impl From<&PtyWriteInstruction> for PtyWriteContext { } } -pub(crate) fn pty_writer_main(bus: Bus<PtyWriteInstruction>) { +pub(crate) fn pty_writer_main(bus: Bus<PtyWriteInstruction>) -> Result<()> { + let err_context = || "failed to write to pty".to_string(); + loop { - let (event, mut err_ctx) = bus.recv().expect("failed to receive event on channel"); + let (event, mut err_ctx) = bus.recv().with_context(err_context)?; err_ctx.add_call(ContextType::PtyWrite((&event).into())); - let os_input = bus.os_input.clone().unwrap(); + let os_input = bus + .os_input + .clone() + .context("no OS input API found") + .with_context(err_context)?; match event { PtyWriteInstruction::Write(bytes, terminal_id) => { - if let Err(e) = os_input.write_to_tty_stdin(terminal_id, &bytes) { - log::error!("failed to write to terminal: {}", e); - } - if let Err(e) = os_input.tcdrain(terminal_id) { - log::error!("failed to drain terminal: {}", e); - }; + os_input + .write_to_tty_stdin(terminal_id, &bytes) + .with_context(err_context) + .non_fatal(); + os_input + .tcdrain(terminal_id) + .with_context(err_context) + .non_fatal(); }, PtyWriteInstruction::Exit => { - break; + return Ok(()); }, } } |