aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/errors.rs
diff options
context:
space:
mode:
authorcategorille <69397914+categorille@users.noreply.github.com>2021-02-17 15:55:09 +0100
committerGitHub <noreply@github.com>2021-02-17 15:55:09 +0100
commit6e5607ba26d8c1daa384d9eb8c6e138b68360d02 (patch)
treeff7cbeaa74dba9692d224f77f6ad5a7fb8a0ac77 /src/common/errors.rs
parentinfra(simplify build and install) (diff)
downloadsl0ppij-6e5607ba26d8c1daa384d9eb8c6e138b68360d02.tar.gz
sl0ppij-6e5607ba26d8c1daa384d9eb8c6e138b68360d02.tar.xz
sl0ppij-6e5607ba26d8c1daa384d9eb8c6e138b68360d02.zip
docs: first documentation step (#185)
* added some documentation to the input module * added a bunch of documentation already, doing this non-linearly * added more comments * forgot cargo ftm again oop * PR change requests applied, some forgotten/imcomplete doc added
Diffstat (limited to 'src/common/errors.rs')
-rw-r--r--src/common/errors.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs
index 27fe3103..3d105dbc 100644
--- a/src/common/errors.rs
+++ b/src/common/errors.rs
@@ -1,15 +1,21 @@
+//! Error context system based on a thread-local representation of the call stack, itself based on
+//! the instructions that are sent between threads.
+
use super::{AppInstruction, OPENCALLS};
use crate::pty_bus::PtyInstruction;
use crate::screen::ScreenInstruction;
use std::fmt::{Display, Error, Formatter};
+/// The maximum amount of calls an [`ErrorContext`] will keep track
+/// of in its stack representation. This is a per-thread maximum.
const MAX_THREAD_CALL_STACK: usize = 6;
#[cfg(not(test))]
use super::SenderWithContext;
#[cfg(not(test))]
use std::panic::PanicInfo;
+/// Custom panic handler/hook. Prints the [`ErrorContext`].
#[cfg(not(test))]
pub fn handle_panic(
info: &PanicInfo<'_>,
@@ -66,18 +72,22 @@ pub fn handle_panic(
}
}
+/// A representation of the call stack.
#[derive(Clone, Copy)]
pub struct ErrorContext {
calls: [ContextType; MAX_THREAD_CALL_STACK],
}
impl ErrorContext {
+ /// Returns a new, blank [`ErrorContext`] containing only [`Empty`](ContextType::Empty)
+ /// calls.
pub fn new() -> Self {
Self {
calls: [ContextType::Empty; MAX_THREAD_CALL_STACK],
}
}
+ /// Adds a call to this [`ErrorContext`]'s call stack representation.
pub fn add_call(&mut self, call: ContextType) {
for ctx in self.calls.iter_mut() {
if *ctx == ContextType::Empty {
@@ -108,19 +118,30 @@ impl Display for ErrorContext {
}
}
+/// Different types of calls that form an [`ErrorContext`] call stack.
+///
+/// Complex variants store a variant of a related enum, whose variants can be built from
+/// the corresponding Zellij MSPC instruction enum variants ([`ScreenInstruction`],
+/// [`PtyInstruction`], [`AppInstruction`], etc).
#[derive(Copy, Clone, PartialEq)]
pub enum ContextType {
+ /// A screen-related call.
Screen(ScreenContext),
+ /// A PTY-related call.
Pty(PtyContext),
-
+ /// A plugin-related call.
Plugin(PluginContext),
+ /// An app-related call.
App(AppContext),
IPCServer,
StdinHandler,
AsyncTask,
+ /// An empty, placeholder call. This should be thought of as representing no call at all.
+ /// A call stack representation filled with these is the representation of an empty call stack.
Empty,
}
+// TODO use the `colored` crate for color formatting
impl Display for ContextType {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
let purple = "\u{1b}[1;35m";
@@ -143,6 +164,7 @@ impl Display for ContextType {
}
}
+/// Stack call representations corresponding to the different types of [`ScreenInstruction`]s.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ScreenContext {
HandlePtyEvent,
@@ -216,6 +238,7 @@ impl From<&ScreenInstruction> for ScreenContext {
}
}
+/// Stack call representations corresponding to the different types of [`PtyInstruction`]s.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PtyContext {
SpawnTerminal,
@@ -245,6 +268,7 @@ impl From<&PtyInstruction> for PtyContext {
use crate::wasm_vm::PluginInstruction;
+/// Stack call representations corresponding to the different types of [`PluginInstruction`]s.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PluginContext {
Load,
@@ -268,6 +292,7 @@ impl From<&PluginInstruction> for PluginContext {
}
}
+/// Stack call representations corresponding to the different types of [`AppInstruction`]s.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AppContext {
GetState,