Re-establish Syncness of Error.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -95,7 +95,7 @@ pub fn trap() {
|
||||
}
|
||||
|
||||
#[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)
|
||||
.downcast_ref::<&str>()
|
||||
.copied()
|
||||
|
||||
@@ -4,16 +4,21 @@ mod panic;
|
||||
mod response;
|
||||
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::*};
|
||||
|
||||
#[derive(thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("PANIC!")]
|
||||
PanicAny(Box<dyn Any + Send>),
|
||||
PanicAny(OnceLock<Box<dyn Any + Send>>),
|
||||
#[error("PANIC! {0}")]
|
||||
Panic(&'static str, Box<dyn Any + Send + 'static>),
|
||||
Panic(&'static str, OnceLock<Box<dyn Any + Send + 'static>>),
|
||||
|
||||
// std
|
||||
#[error(transparent)]
|
||||
@@ -27,7 +32,7 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
ParseInt(#[from] std::num::ParseIntError),
|
||||
#[error(transparent)]
|
||||
Std(#[from] Box<dyn std::error::Error + Send>),
|
||||
Std(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
#[error(transparent)]
|
||||
SystemTime(#[from] std::time::SystemTimeError),
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -15,13 +15,16 @@ impl Error {
|
||||
|
||||
#[must_use]
|
||||
#[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]
|
||||
pub fn into_panic(self) -> Box<dyn Any + Send + 'static> {
|
||||
pub fn into_panic(self) -> Box<dyn Any + Send> {
|
||||
match self {
|
||||
| Self::Panic(_, e) | Self::PanicAny(e) => e,
|
||||
| Self::JoinError(e) => e.into_panic(),
|
||||
| Self::Panic(_, mut e) | Self::PanicAny(mut e) =>
|
||||
e.take().expect("Error contained panic"),
|
||||
| _ => Box::new(self),
|
||||
}
|
||||
}
|
||||
@@ -29,16 +32,18 @@ impl Error {
|
||||
/// Get the panic message string.
|
||||
#[inline]
|
||||
pub fn panic_str(self) -> Option<&'static str> {
|
||||
self.is_panic()
|
||||
.then_some(debug::panic_str(&self.into_panic()))
|
||||
self.is_panic().then(|| {
|
||||
let panic = self.into_panic();
|
||||
debug::panic_str(&panic)
|
||||
})
|
||||
}
|
||||
|
||||
/// Check if the Error is trafficking a panic object.
|
||||
#[inline]
|
||||
pub fn is_panic(&self) -> bool {
|
||||
match &self {
|
||||
| Self::Panic(..) | Self::PanicAny(..) => true,
|
||||
| Self::JoinError(e) => e.is_panic(),
|
||||
| Self::Panic(..) | Self::PanicAny(..) => true,
|
||||
| _ => false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user