diff options
author | Hyper <HyperHamster@users.noreply.github.com> | 2023-12-30 09:12:00 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-30 19:12:00 +0400 |
commit | b067fcca337377a751880744b71a6576501dcdd1 (patch) | |
tree | 9492e79208ea50dbc9bedf1a91d616c32e509860 | |
parent | 85d85e49b2a9c3979b2bd12a78cfe0af4ca10b30 (diff) | |
download | alacritty-b067fcca337377a751880744b71a6576501dcdd1.tar.gz alacritty-b067fcca337377a751880744b71a6576501dcdd1.zip |
Passthrough potential errors for `EventLoopSender`
-rw-r--r-- | alacritty/src/window_context.rs | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/event_loop.rs | 38 |
2 files changed, 34 insertions, 6 deletions
diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index 724a5515..c87c2210 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -560,6 +560,6 @@ impl WindowContext { impl Drop for WindowContext { fn drop(&mut self) { // Shutdown the terminal's PTY. - self.notifier.0.send(Msg::Shutdown); + let _ = self.notifier.0.send(Msg::Shutdown); } } diff --git a/alacritty_terminal/src/event_loop.rs b/alacritty_terminal/src/event_loop.rs index 21ab027c..57045f4a 100644 --- a/alacritty_terminal/src/event_loop.rs +++ b/alacritty_terminal/src/event_loop.rs @@ -2,6 +2,7 @@ use std::borrow::Cow; use std::collections::VecDeque; +use std::fmt::{self, Display, Formatter}; use std::fs::File; use std::io::{self, ErrorKind, Read, Write}; use std::marker::Send; @@ -339,13 +340,40 @@ impl event::Notify for Notifier { return; } - self.0.send(Msg::Input(bytes)); + let _ = self.0.send(Msg::Input(bytes)); } } impl event::OnResize for Notifier { fn on_resize(&mut self, window_size: WindowSize) { - self.0.send(Msg::Resize(window_size)); + let _ = self.0.send(Msg::Resize(window_size)); + } +} + +#[derive(Debug)] +pub enum EventLoopSendError { + /// Error polling the event loop. + Io(io::Error), + + /// Error sending a message to the event loop. + Send(mpsc::SendError<Msg>), +} + +impl Display for EventLoopSendError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + EventLoopSendError::Io(err) => err.fmt(f), + EventLoopSendError::Send(err) => err.fmt(f), + } + } +} + +impl std::error::Error for EventLoopSendError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + EventLoopSendError::Io(err) => err.source(), + EventLoopSendError::Send(err) => err.source(), + } } } @@ -356,9 +384,9 @@ pub struct EventLoopSender { } impl EventLoopSender { - pub fn send(&self, msg: Msg) { - let _ = self.sender.send(msg); - let _ = self.poller.notify(); + pub fn send(&self, msg: Msg) -> Result<(), EventLoopSendError> { + self.sender.send(msg).map_err(EventLoopSendError::Send)?; + self.poller.notify().map_err(EventLoopSendError::Io) } } |