Re-establish Syncness of Error.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-11-25 06:43:18 +00:00
parent e5073165f0
commit 98affbdeaf
3 changed files with 21 additions and 11 deletions

View File

@@ -95,7 +95,7 @@ pub fn trap() {
} }
#[must_use] #[must_use]
pub fn panic_str(p: &Box<dyn Any + Send>) -> &'static str { pub fn panic_str(p: &Box<dyn Any + Send + 'static>) -> &'static str {
(**p) (**p)
.downcast_ref::<&str>() .downcast_ref::<&str>()
.copied() .copied()

View File

@@ -4,16 +4,21 @@ mod panic;
mod response; mod response;
mod serde; mod serde;
use std::{any::Any, borrow::Cow, convert::Infallible, sync::PoisonError}; use std::{
any::Any,
borrow::Cow,
convert::Infallible,
sync::{OnceLock, PoisonError},
};
pub use self::{err::visit, log::*}; pub use self::{err::visit, log::*};
#[derive(thiserror::Error)] #[derive(thiserror::Error)]
pub enum Error { pub enum Error {
#[error("PANIC!")] #[error("PANIC!")]
PanicAny(Box<dyn Any + Send>), PanicAny(OnceLock<Box<dyn Any + Send>>),
#[error("PANIC! {0}")] #[error("PANIC! {0}")]
Panic(&'static str, Box<dyn Any + Send + 'static>), Panic(&'static str, OnceLock<Box<dyn Any + Send + 'static>>),
// std // std
#[error(transparent)] #[error(transparent)]
@@ -27,7 +32,7 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
ParseInt(#[from] std::num::ParseIntError), ParseInt(#[from] std::num::ParseIntError),
#[error(transparent)] #[error(transparent)]
Std(#[from] Box<dyn std::error::Error + Send>), Std(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
#[error(transparent)] #[error(transparent)]
SystemTime(#[from] std::time::SystemTimeError), SystemTime(#[from] std::time::SystemTimeError),
#[error(transparent)] #[error(transparent)]

View File

@@ -15,13 +15,16 @@ impl Error {
#[must_use] #[must_use]
#[inline] #[inline]
pub fn from_panic(e: Box<dyn Any + Send>) -> Self { Self::Panic(debug::panic_str(&e), e) } pub fn from_panic(e: Box<dyn Any + Send + 'static>) -> Self {
Self::Panic(debug::panic_str(&e), e.into())
}
#[inline] #[inline]
pub fn into_panic(self) -> Box<dyn Any + Send + 'static> { pub fn into_panic(self) -> Box<dyn Any + Send> {
match self { match self {
| Self::Panic(_, e) | Self::PanicAny(e) => e,
| Self::JoinError(e) => e.into_panic(), | Self::JoinError(e) => e.into_panic(),
| Self::Panic(_, mut e) | Self::PanicAny(mut e) =>
e.take().expect("Error contained panic"),
| _ => Box::new(self), | _ => Box::new(self),
} }
} }
@@ -29,16 +32,18 @@ impl Error {
/// Get the panic message string. /// Get the panic message string.
#[inline] #[inline]
pub fn panic_str(self) -> Option<&'static str> { pub fn panic_str(self) -> Option<&'static str> {
self.is_panic() self.is_panic().then(|| {
.then_some(debug::panic_str(&self.into_panic())) let panic = self.into_panic();
debug::panic_str(&panic)
})
} }
/// Check if the Error is trafficking a panic object. /// Check if the Error is trafficking a panic object.
#[inline] #[inline]
pub fn is_panic(&self) -> bool { pub fn is_panic(&self) -> bool {
match &self { match &self {
| Self::Panic(..) | Self::PanicAny(..) => true,
| Self::JoinError(e) => e.is_panic(), | Self::JoinError(e) => e.is_panic(),
| Self::Panic(..) | Self::PanicAny(..) => true,
| _ => false, | _ => false,
} }
} }