aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/thread_bus.rs
diff options
context:
space:
mode:
authorBohdan Ivashko <20084245+arriven@users.noreply.github.com>2022-10-07 12:04:08 +0300
committerGitHub <noreply@github.com>2022-10-07 09:04:08 +0000
commit39f33a9a9a47bd7e22bff4c1ec3a0a1456ca30e8 (patch)
treee9748725333be40d4ec88606c254b2c35deafcf6 /zellij-server/src/thread_bus.rs
parentchangelog: Add pull 1748 (diff)
downloadsl0ppij-39f33a9a9a47bd7e22bff4c1ec3a0a1456ca30e8.tar.gz
sl0ppij-39f33a9a9a47bd7e22bff4c1ec3a0a1456ca30e8.tar.xz
sl0ppij-39f33a9a9a47bd7e22bff4c1ec3a0a1456ca30e8.zip
zellij-server: improve thread_bus error handling (#1775)
* zellij-server: improve thread_bus error handling * zellij-server/thread_bus: get rid of option.unwrap * zellij-utils/errors.rs: generic error in to_anyhow
Diffstat (limited to 'zellij-server/src/thread_bus.rs')
-rw-r--r--zellij-server/src/thread_bus.rs61
1 files changed, 36 insertions, 25 deletions
diff --git a/zellij-server/src/thread_bus.rs b/zellij-server/src/thread_bus.rs
index 21ddecfe..0b6311e9 100644
--- a/zellij-server/src/thread_bus.rs
+++ b/zellij-server/src/thread_bus.rs
@@ -4,6 +4,7 @@ use crate::{
os_input_output::ServerOsApi, pty::PtyInstruction, pty_writer::PtyWriteInstruction,
screen::ScreenInstruction, wasm_vm::PluginInstruction, ServerInstruction,
};
+use zellij_utils::errors::prelude::*;
use zellij_utils::{channels, channels::SenderWithContext, errors::ErrorContext};
/// A container for senders to the different threads in zellij on the server side
@@ -20,10 +21,7 @@ pub(crate) struct ThreadSenders {
}
impl ThreadSenders {
- pub fn send_to_screen(
- &self,
- instruction: ScreenInstruction,
- ) -> Result<(), channels::SendError<(ScreenInstruction, ErrorContext)>> {
+ pub fn send_to_screen(&self, instruction: ScreenInstruction) -> Result<()> {
if self.should_silently_fail {
let _ = self
.to_screen
@@ -32,14 +30,16 @@ impl ThreadSenders {
.unwrap_or_else(|| Ok(()));
Ok(())
} else {
- self.to_screen.as_ref().unwrap().send(instruction)
+ self.to_screen
+ .as_ref()
+ .context("failed to get screen sender")?
+ .send(instruction)
+ .to_anyhow()
+ .context("failed to send message to screen")
}
}
- pub fn send_to_pty(
- &self,
- instruction: PtyInstruction,
- ) -> Result<(), channels::SendError<(PtyInstruction, ErrorContext)>> {
+ pub fn send_to_pty(&self, instruction: PtyInstruction) -> Result<()> {
if self.should_silently_fail {
let _ = self
.to_pty
@@ -48,14 +48,16 @@ impl ThreadSenders {
.unwrap_or_else(|| Ok(()));
Ok(())
} else {
- self.to_pty.as_ref().unwrap().send(instruction)
+ self.to_pty
+ .as_ref()
+ .context("failed to get pty sender")?
+ .send(instruction)
+ .to_anyhow()
+ .context("failed to send message to pty")
}
}
- pub fn send_to_plugin(
- &self,
- instruction: PluginInstruction,
- ) -> Result<(), channels::SendError<(PluginInstruction, ErrorContext)>> {
+ pub fn send_to_plugin(&self, instruction: PluginInstruction) -> Result<()> {
if self.should_silently_fail {
let _ = self
.to_plugin
@@ -64,14 +66,16 @@ impl ThreadSenders {
.unwrap_or_else(|| Ok(()));
Ok(())
} else {
- self.to_plugin.as_ref().unwrap().send(instruction)
+ self.to_plugin
+ .as_ref()
+ .context("failed to get plugin sender")?
+ .send(instruction)
+ .to_anyhow()
+ .context("failed to send message to plugin")
}
}
- pub fn send_to_server(
- &self,
- instruction: ServerInstruction,
- ) -> Result<(), channels::SendError<(ServerInstruction, ErrorContext)>> {
+ pub fn send_to_server(&self, instruction: ServerInstruction) -> Result<()> {
if self.should_silently_fail {
let _ = self
.to_server
@@ -80,13 +84,15 @@ impl ThreadSenders {
.unwrap_or_else(|| Ok(()));
Ok(())
} else {
- self.to_server.as_ref().unwrap().send(instruction)
+ self.to_server
+ .as_ref()
+ .context("failed to get server sender")?
+ .send(instruction)
+ .to_anyhow()
+ .context("failed to send message to server")
}
}
- pub fn send_to_pty_writer(
- &self,
- instruction: PtyWriteInstruction,
- ) -> Result<(), channels::SendError<(PtyWriteInstruction, ErrorContext)>> {
+ pub fn send_to_pty_writer(&self, instruction: PtyWriteInstruction) -> Result<()> {
if self.should_silently_fail {
let _ = self
.to_pty_writer
@@ -95,7 +101,12 @@ impl ThreadSenders {
.unwrap_or_else(|| Ok(()));
Ok(())
} else {
- self.to_pty_writer.as_ref().unwrap().send(instruction)
+ self.to_pty_writer
+ .as_ref()
+ .context("failed to get pty writer sender")?
+ .send(instruction)
+ .to_anyhow()
+ .context("failed to send message to pty writer")
}
}