From cdc3c027f5b0c1c105964a06f5b1fe60cac058c5 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 1 Feb 2024 23:19:23 -0700 Subject: [PATCH] Fix unnecessary explicit panic in PTY Closes #7680. --- alacritty/src/window_context.rs | 2 +- alacritty_terminal/src/event_loop.rs | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index 3f3e6807d6..891551bbf6 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -223,7 +223,7 @@ impl WindowContext { pty, pty_config.hold, config.debug.ref_test, - ); + )?; // The event loop channel allows write requests from the event processor // to be sent to the pty loop and ultimately written to the pty. diff --git a/alacritty_terminal/src/event_loop.rs b/alacritty_terminal/src/event_loop.rs index 57045f4a30..42025b009d 100644 --- a/alacritty_terminal/src/event_loop.rs +++ b/alacritty_terminal/src/event_loop.rs @@ -67,10 +67,11 @@ where pty: T, hold: bool, ref_test: bool, - ) -> EventLoop { + ) -> io::Result> { let (tx, rx) = mpsc::channel(); - EventLoop { - poll: polling::Poller::new().expect("create Poll").into(), + let poll = polling::Poller::new()?.into(); + Ok(EventLoop { + poll, pty, tx, rx: PeekableReceiver::new(rx), @@ -78,7 +79,7 @@ where event_proxy, hold, ref_test, - } + }) } pub fn channel(&self) -> EventLoopSender { @@ -213,8 +214,9 @@ where let mut interest = PollingEvent::readable(0); // Register TTY through EventedRW interface. - unsafe { - self.pty.register(&self.poll, interest, poll_opts).unwrap(); + if let Err(err) = unsafe { self.pty.register(&self.poll, interest, poll_opts) } { + error!("Event loop registration error: {}", err); + return (self, state); } let mut events = Events::with_capacity(NonZeroUsize::new(1024).unwrap()); @@ -235,7 +237,10 @@ where if let Err(err) = self.poll.wait(&mut events, timeout) { match err.kind() { ErrorKind::Interrupted => continue, - _ => panic!("EventLoop polling error: {err:?}"), + _ => { + error!("Event loop polling error: {}", err); + break 'event_loop; + }, } }