reduce Error-related codegen; add PoisonError
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
52f09fdb51
commit
8d251003a2
5 changed files with 16 additions and 1 deletions
|
@ -2001,6 +2001,7 @@ fn default_rocksdb_stats_level() -> u8 { 1 }
|
||||||
|
|
||||||
// I know, it's a great name
|
// I know, it's a great name
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
pub fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 }
|
pub fn default_default_room_version() -> RoomVersionId { RoomVersionId::V10 }
|
||||||
|
|
||||||
fn default_ip_range_denylist() -> Vec<String> {
|
fn default_ip_range_denylist() -> Vec<String> {
|
||||||
|
|
|
@ -137,6 +137,7 @@ macro_rules! err_log {
|
||||||
let visit = &mut |vs: ValueSet<'_>| {
|
let visit = &mut |vs: ValueSet<'_>| {
|
||||||
struct Visitor<'a>(&'a mut String);
|
struct Visitor<'a>(&'a mut String);
|
||||||
impl Visit for Visitor<'_> {
|
impl Visit for Visitor<'_> {
|
||||||
|
#[inline]
|
||||||
fn record_debug(&mut self, field: &Field, val: &dyn fmt::Debug) {
|
fn record_debug(&mut self, field: &Field, val: &dyn fmt::Debug) {
|
||||||
if field.name() == "message" {
|
if field.name() == "message" {
|
||||||
write!(self.0, "{:?}", val).expect("stream error");
|
write!(self.0, "{:?}", val).expect("stream error");
|
||||||
|
|
|
@ -4,7 +4,7 @@ mod panic;
|
||||||
mod response;
|
mod response;
|
||||||
mod serde;
|
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::*;
|
pub use self::log::*;
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
@ -59,6 +59,8 @@ pub enum Error {
|
||||||
JsTryFromInt(#[from] ruma::JsTryFromIntError), // js_int re-export
|
JsTryFromInt(#[from] ruma::JsTryFromIntError), // js_int re-export
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Path(#[from] axum::extract::rejection::PathRejection),
|
Path(#[from] axum::extract::rejection::PathRejection),
|
||||||
|
#[error("Mutex poisoned: {0}")]
|
||||||
|
Poison(Cow<'static, str>),
|
||||||
#[error("Regex error: {0}")]
|
#[error("Regex error: {0}")]
|
||||||
Regex(#[from] regex::Error),
|
Regex(#[from] regex::Error),
|
||||||
#[error("Request error: {0}")]
|
#[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()) }
|
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)]
|
#[allow(clippy::fallible_impl_from)]
|
||||||
impl From<Infallible> for Error {
|
impl From<Infallible> for Error {
|
||||||
#[cold]
|
#[cold]
|
||||||
|
|
|
@ -10,11 +10,14 @@ impl UnwindSafe for Error {}
|
||||||
impl RefUnwindSafe for Error {}
|
impl RefUnwindSafe for Error {}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
#[inline]
|
||||||
pub fn panic(self) -> ! { panic_any(self.into_panic()) }
|
pub fn panic(self) -> ! { panic_any(self.into_panic()) }
|
||||||
|
|
||||||
#[must_use]
|
#[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>) -> Self { Self::Panic(debug::panic_str(&e), e) }
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn into_panic(self) -> Box<dyn Any + Send + 'static> {
|
pub fn into_panic(self) -> Box<dyn Any + Send + 'static> {
|
||||||
match self {
|
match self {
|
||||||
Self::Panic(_, e) | Self::PanicAny(e) => e,
|
Self::Panic(_, e) | Self::PanicAny(e) => e,
|
||||||
|
@ -24,6 +27,7 @@ impl Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the panic message string.
|
/// Get the panic message string.
|
||||||
|
#[inline]
|
||||||
pub fn panic_str(self) -> Option<&'static str> {
|
pub fn panic_str(self) -> Option<&'static str> {
|
||||||
self.is_panic()
|
self.is_panic()
|
||||||
.then_some(debug::panic_str(&self.into_panic()))
|
.then_some(debug::panic_str(&self.into_panic()))
|
||||||
|
|
|
@ -26,6 +26,7 @@ impl axum::response::IntoResponse for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Error> for UiaaResponse {
|
impl From<Error> for UiaaResponse {
|
||||||
|
#[inline]
|
||||||
fn from(error: Error) -> Self {
|
fn from(error: Error) -> Self {
|
||||||
if let Error::Uiaa(uiaainfo) = error {
|
if let Error::Uiaa(uiaainfo) = error {
|
||||||
return Self::AuthResponse(uiaainfo);
|
return Self::AuthResponse(uiaainfo);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue