diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2023-01-19 18:17:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 18:17:33 +0000 |
commit | b274fc5ab19abe8b3ef7f7afe38897f526263414 (patch) | |
tree | baf1ae9cc8407da95558ad827d63d6de5c964979 /zellij-utils/src/errors.rs | |
parent | 670b9c27597c656cd457be8a41e6548d007b4feb (diff) |
errors: handle missing plugin caches (#2093)
* server/plugins: Always recreate plugin folders
in case they aren't existent and don't mark errors to do so as
non-fatal. The latter masks the underlying cause when e.g. the `.cache`
folder is, for some reason, not writable by zellij (See #2092), whereas
the former fixes problems arising from the user having purged their
.cache/zellij folder entirely.
* utils/errors: Rewrite panic message
* changelog: Add PR #2093
Diffstat (limited to 'zellij-utils/src/errors.rs')
-rw-r--r-- | zellij-utils/src/errors.rs | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index d0e4fad25..7fbed99ed 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -16,9 +16,6 @@ use serde::{Deserialize, Serialize}; use std::fmt::{Display, Error, Formatter}; use std::path::PathBuf; -use miette::Diagnostic; -use thiserror::Error as ThisError; - /// Re-exports of common error-handling code. pub mod prelude { pub use super::FatalError; @@ -37,39 +34,6 @@ pub trait ErrorInstruction { fn error(err: String) -> Self; } -#[derive(Debug, ThisError, Diagnostic)] -#[error("{0}{}", self.show_backtrace())] -#[diagnostic(help("{}", self.show_help()))] -struct Panic(String); - -impl Panic { - // We already capture a backtrace with `anyhow` using the `backtrace` crate in the background. - // The advantage is that this is the backtrace of the real errors source (i.e. where we first - // encountered the error and turned it into an `anyhow::Error`), whereas the backtrace recorded - // here is the backtrace leading to the call to any `panic`ing function. Since now we propagate - // errors up before `unwrap`ing them (e.g. in `zellij_server::screen::screen_thread_main`), the - // former is what we really want to diagnose. - // We still keep the second one around just in case the first backtrace isn't meaningful or - // non-existent in the first place (Which really shouldn't happen, but you never know). - fn show_backtrace(&self) -> String { - if let Ok(var) = std::env::var("RUST_BACKTRACE") { - if !var.is_empty() && var != "0" { - return format!("\n\nPanic backtrace:\n{:?}", backtrace::Backtrace::new()); - } - } - "".into() - } - - fn show_help(&self) -> String { - r#"If you are seeing this message, it means that something went wrong. -Please report this error to the github issue. -(https://github.com/zellij-org/zellij/issues) - -Also, if you want to see the backtrace, you can set the `RUST_BACKTRACE` environment variable to `1`. -"#.into() - } -} - /// Helper trait to easily log error types. /// /// The `print_error` function takes a closure which takes a `&str` and fares with it as necessary @@ -514,13 +478,51 @@ pub use not_wasm::*; mod not_wasm { use super::*; use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS}; - use miette::{GraphicalReportHandler, GraphicalTheme, Report}; + use miette::{Diagnostic, GraphicalReportHandler, GraphicalTheme, Report}; use std::panic::PanicInfo; + use thiserror::Error as ThisError; /// 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; + #[derive(Debug, ThisError, Diagnostic)] + #[error("{0}{}", self.show_backtrace())] + #[diagnostic(help("{}", self.show_help()))] + struct Panic(String); + + impl Panic { + // We already capture a backtrace with `anyhow` using the `backtrace` crate in the background. + // The advantage is that this is the backtrace of the real errors source (i.e. where we first + // encountered the error and turned it into an `anyhow::Error`), whereas the backtrace recorded + // here is the backtrace leading to the call to any `panic`ing function. Since now we propagate + // errors up before `unwrap`ing them (e.g. in `zellij_server::screen::screen_thread_main`), the + // former is what we really want to diagnose. + // We still keep the second one around just in case the first backtrace isn't meaningful or + // non-existent in the first place (Which really shouldn't happen, but you never know). + fn show_backtrace(&self) -> String { + if let Ok(var) = std::env::var("RUST_BACKTRACE") { + if !var.is_empty() && var != "0" { + return format!("\n\nPanic backtrace:\n{:?}", backtrace::Backtrace::new()); + } + } + "".into() + } + + fn show_help(&self) -> String { + format!( + "If you are seeing this message, it means that something went wrong. + +-> To get additional information, check the log at: {} +-> To see a backtrace next time, reproduce the error with: RUST_BACKTRACE=1 zellij [...] +-> To help us fix this, please open an issue: https://github.com/zellij-org/zellij/issues + +", + crate::consts::ZELLIJ_TMP_LOG_FILE.display().to_string() + ) + } + } + /// Custom panic handler/hook. Prints the [`ErrorContext`]. pub fn handle_panic<T>(info: &PanicInfo<'_>, sender: &SenderWithContext<T>) where |