aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/errors.rs
diff options
context:
space:
mode:
authora-kenji <aks.kenji@protonmail.com>2021-05-16 12:44:56 +0200
committera-kenji <aks.kenji@protonmail.com>2021-05-16 12:44:56 +0200
commit197f31875646a5b78abd23edecee072931b2b14b (patch)
treea8fb17d057d77c0a5090c5e1878ecd5618ec592d /src/common/errors.rs
parentSplit Layout Flag (diff)
parentDocs(changelog): Multiprocess model #499 (diff)
downloadsl0ppij-197f31875646a5b78abd23edecee072931b2b14b.tar.gz
sl0ppij-197f31875646a5b78abd23edecee072931b2b14b.tar.xz
sl0ppij-197f31875646a5b78abd23edecee072931b2b14b.zip
Merge branch 'main' of https://github.com/zellij-org/zellij into layout-path-506
Diffstat (limited to 'src/common/errors.rs')
-rw-r--r--src/common/errors.rs40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs
index c2caf19d..262dfd6b 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -19,12 +19,29 @@ const MAX_THREAD_CALL_STACK: usize = 6;
use super::thread_bus::SenderWithContext;
#[cfg(not(test))]
use std::panic::PanicInfo;
+
+pub trait ErrorInstruction {
+ fn error(err: String) -> Self;
+}
+
+impl ErrorInstruction for ClientInstruction {
+ fn error(err: String) -> Self {
+ ClientInstruction::Error(err)
+ }
+}
+
+impl ErrorInstruction for ServerInstruction {
+ fn error(err: String) -> Self {
+ ServerInstruction::Error(err)
+ }
+}
+
/// Custom panic handler/hook. Prints the [`ErrorContext`].
#[cfg(not(test))]
-pub fn handle_panic(
- info: &PanicInfo<'_>,
- send_app_instructions: &SenderWithContext<ClientInstruction>,
-) {
+pub fn handle_panic<T>(info: &PanicInfo<'_>, sender: &SenderWithContext<T>)
+where
+ T: ErrorInstruction + Clone,
+{
use backtrace::Backtrace;
use std::{process, thread};
let backtrace = Backtrace::new();
@@ -70,7 +87,7 @@ pub fn handle_panic(
println!("{}", backtrace);
process::exit(1);
} else {
- let _ = send_app_instructions.send(ClientInstruction::Error(backtrace));
+ let _ = sender.send(T::error(backtrace));
}
}
@@ -103,6 +120,11 @@ impl ErrorContext {
break;
}
}
+ self.update_thread_ctx()
+ }
+
+ /// Updates the thread local [`ErrorContext`].
+ pub fn update_thread_ctx(&self) {
ASYNCOPENCALLS
.try_with(|ctx| *ctx.borrow_mut() = *self)
.unwrap_or_else(|_| OPENCALLS.with(|ctx| *ctx.borrow_mut() = *self));
@@ -333,6 +355,7 @@ pub enum ClientContext {
Error,
UnblockInputThread,
Render,
+ ServerError,
}
impl From<&ClientInstruction> for ClientContext {
@@ -340,6 +363,7 @@ impl From<&ClientInstruction> for ClientContext {
match *client_instruction {
ClientInstruction::Exit => ClientContext::Exit,
ClientInstruction::Error(_) => ClientContext::Error,
+ ClientInstruction::ServerError(_) => ClientContext::ServerError,
ClientInstruction::Render(_) => ClientContext::Render,
ClientInstruction::UnblockInputThread => ClientContext::UnblockInputThread,
}
@@ -350,22 +374,20 @@ impl From<&ClientInstruction> for ClientContext {
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum ServerContext {
NewClient,
- Action,
Render,
- TerminalResize,
UnblockInputThread,
ClientExit,
+ Error,
}
impl From<&ServerInstruction> for ServerContext {
fn from(server_instruction: &ServerInstruction) -> Self {
match *server_instruction {
ServerInstruction::NewClient(..) => ServerContext::NewClient,
- ServerInstruction::Action(_) => ServerContext::Action,
- ServerInstruction::TerminalResize(_) => ServerContext::TerminalResize,
ServerInstruction::Render(_) => ServerContext::Render,
ServerInstruction::UnblockInputThread => ServerContext::UnblockInputThread,
ServerInstruction::ClientExit => ServerContext::ClientExit,
+ ServerInstruction::Error(_) => ServerContext::Error,
}
}
}