reduce Error-related codegen; add PoisonError

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk committed 2024-11-03 14:51:07 +00:00
1 parent 52f09fdb51
commit 8d251003a2
5 files changed
+16 -1

No files matched your search

+9 -1
View File
@@ -4,7 +4,7 @@ mod panic;
mod response;
mod serde;
use std::{any::Any, borrow::Cow, convert::Infallible, fmt};
use std::{any::Any, borrow::Cow, convert::Infallible, fmt, sync::PoisonError};
pub use self::log::*;
use crate::error;
@@ -59,6 +59,8 @@ pub enum Error {
JsTryFromInt(#[from] ruma::JsTryFromIntError), // js_int re-export
#[error(transparent)]
Path(#[from] axum::extract::rejection::PathRejection),
#[error("Mutex poisoned: {0}")]
Poison(Cow<'static, str>),
#[error("Regex error: {0}")]
Regex(#[from] regex::Error),
#[error("Request error: {0}")]
@@ -184,6 +186,12 @@ impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.message()) }
}
impl<T> From<PoisonError<T>> for Error {
#[cold]
#[inline(never)]
fn from(e: PoisonError<T>) -> Self { Self::Poison(e.to_string().into()) }
}
#[allow(clippy::fallible_impl_from)]
impl From<Infallible> for Error {
#[cold]