apply new rustfmt.toml changes, fix some clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0317cc8cc5
commit
77e0b76408
296 changed files with 7147 additions and 4300 deletions
|
@ -184,7 +184,12 @@ impl Visit for Visitor<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn visit(out: &mut String, level: Level, __callsite: &'static DefaultCallsite, vs: &mut ValueSet<'_>) {
|
||||
pub fn visit(
|
||||
out: &mut String,
|
||||
level: Level,
|
||||
__callsite: &'static DefaultCallsite,
|
||||
vs: &mut ValueSet<'_>,
|
||||
) {
|
||||
let meta = __callsite.metadata();
|
||||
let enabled = level_enabled!(level) && {
|
||||
let interest = __callsite.interest();
|
||||
|
|
|
@ -68,18 +68,20 @@ where
|
|||
pub fn inspect_log<E: fmt::Display>(error: &E) { inspect_log_level(error, Level::ERROR); }
|
||||
|
||||
#[inline]
|
||||
pub fn inspect_debug_log<E: fmt::Debug>(error: &E) { inspect_debug_log_level(error, Level::ERROR); }
|
||||
pub fn inspect_debug_log<E: fmt::Debug>(error: &E) {
|
||||
inspect_debug_log_level(error, Level::ERROR);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inspect_log_level<E: fmt::Display>(error: &E, level: Level) {
|
||||
use crate::{debug, error, info, trace, warn};
|
||||
|
||||
match level {
|
||||
Level::ERROR => error!("{error}"),
|
||||
Level::WARN => warn!("{error}"),
|
||||
Level::INFO => info!("{error}"),
|
||||
Level::DEBUG => debug!("{error}"),
|
||||
Level::TRACE => trace!("{error}"),
|
||||
| Level::ERROR => error!("{error}"),
|
||||
| Level::WARN => warn!("{error}"),
|
||||
| Level::INFO => info!("{error}"),
|
||||
| Level::DEBUG => debug!("{error}"),
|
||||
| Level::TRACE => trace!("{error}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,10 +90,10 @@ pub fn inspect_debug_log_level<E: fmt::Debug>(error: &E, level: Level) {
|
|||
use crate::{debug, debug_error, debug_info, debug_warn, trace};
|
||||
|
||||
match level {
|
||||
Level::ERROR => debug_error!("{error:?}"),
|
||||
Level::WARN => debug_warn!("{error:?}"),
|
||||
Level::INFO => debug_info!("{error:?}"),
|
||||
Level::DEBUG => debug!("{error:?}"),
|
||||
Level::TRACE => trace!("{error:?}"),
|
||||
| Level::ERROR => debug_error!("{error:?}"),
|
||||
| Level::WARN => debug_warn!("{error:?}"),
|
||||
| Level::INFO => debug_info!("{error:?}"),
|
||||
| Level::DEBUG => debug!("{error:?}"),
|
||||
| Level::TRACE => trace!("{error:?}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,23 +128,25 @@ pub enum Error {
|
|||
|
||||
impl Error {
|
||||
//#[deprecated]
|
||||
pub fn bad_database(message: &'static str) -> Self { crate::err!(Database(error!("{message}"))) }
|
||||
pub fn bad_database(message: &'static str) -> Self {
|
||||
crate::err!(Database(error!("{message}")))
|
||||
}
|
||||
|
||||
/// Sanitizes public-facing errors that can leak sensitive information.
|
||||
pub fn sanitized_message(&self) -> String {
|
||||
match self {
|
||||
Self::Database(..) => String::from("Database error occurred."),
|
||||
Self::Io(..) => String::from("I/O error occurred."),
|
||||
_ => self.message(),
|
||||
| Self::Database(..) => String::from("Database error occurred."),
|
||||
| Self::Io(..) => String::from("I/O error occurred."),
|
||||
| _ => self.message(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the error message string.
|
||||
pub fn message(&self) -> String {
|
||||
match self {
|
||||
Self::Federation(ref origin, ref error) => format!("Answer from {origin}: {error}"),
|
||||
Self::Ruma(ref error) => response::ruma_error_message(error),
|
||||
_ => format!("{self}"),
|
||||
| Self::Federation(ref origin, ref error) => format!("Answer from {origin}: {error}"),
|
||||
| Self::Ruma(ref error) => response::ruma_error_message(error),
|
||||
| _ => format!("{self}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,9 +156,10 @@ impl Error {
|
|||
use ruma::api::client::error::ErrorKind::Unknown;
|
||||
|
||||
match self {
|
||||
Self::Federation(_, error) | Self::Ruma(error) => response::ruma_error_kind(error).clone(),
|
||||
Self::BadRequest(kind, ..) | Self::Request(kind, ..) => kind.clone(),
|
||||
_ => Unknown,
|
||||
| Self::Federation(_, error) | Self::Ruma(error) =>
|
||||
response::ruma_error_kind(error).clone(),
|
||||
| Self::BadRequest(kind, ..) | Self::Request(kind, ..) => kind.clone(),
|
||||
| _ => Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,12 +169,12 @@ impl Error {
|
|||
use http::StatusCode;
|
||||
|
||||
match self {
|
||||
Self::Federation(_, error) | Self::Ruma(error) => error.status_code,
|
||||
Self::Request(kind, _, code) => response::status_code(kind, *code),
|
||||
Self::BadRequest(kind, ..) => response::bad_request_code(kind),
|
||||
Self::Reqwest(error) => error.status().unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
Self::Conflict(_) => StatusCode::CONFLICT,
|
||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
| Self::Federation(_, error) | Self::Ruma(error) => error.status_code,
|
||||
| Self::Request(kind, _, code) => response::status_code(kind, *code),
|
||||
| Self::BadRequest(kind, ..) => response::bad_request_code(kind),
|
||||
| Self::Reqwest(error) => error.status().unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
| Self::Conflict(_) => StatusCode::CONFLICT,
|
||||
| _ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,9 @@ impl Error {
|
|||
#[inline]
|
||||
pub fn into_panic(self) -> Box<dyn Any + Send + 'static> {
|
||||
match self {
|
||||
Self::Panic(_, e) | Self::PanicAny(e) => e,
|
||||
Self::JoinError(e) => e.into_panic(),
|
||||
_ => Box::new(self),
|
||||
| Self::Panic(_, e) | Self::PanicAny(e) => e,
|
||||
| Self::JoinError(e) => e.into_panic(),
|
||||
| _ => Box::new(self),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,9 @@ impl Error {
|
|||
#[inline]
|
||||
pub fn is_panic(&self) -> bool {
|
||||
match &self {
|
||||
Self::Panic(..) | Self::PanicAny(..) => true,
|
||||
Self::JoinError(e) => e.is_panic(),
|
||||
_ => false,
|
||||
| Self::Panic(..) | Self::PanicAny(..) => true,
|
||||
| Self::JoinError(e) => e.is_panic(),
|
||||
| _ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,49 +57,35 @@ pub(super) fn bad_request_code(kind: &ErrorKind) -> StatusCode {
|
|||
|
||||
match kind {
|
||||
// 429
|
||||
LimitExceeded {
|
||||
..
|
||||
} => StatusCode::TOO_MANY_REQUESTS,
|
||||
| LimitExceeded { .. } => StatusCode::TOO_MANY_REQUESTS,
|
||||
|
||||
// 413
|
||||
TooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
||||
| TooLarge => StatusCode::PAYLOAD_TOO_LARGE,
|
||||
|
||||
// 405
|
||||
Unrecognized => StatusCode::METHOD_NOT_ALLOWED,
|
||||
| Unrecognized => StatusCode::METHOD_NOT_ALLOWED,
|
||||
|
||||
// 404
|
||||
NotFound => StatusCode::NOT_FOUND,
|
||||
| NotFound => StatusCode::NOT_FOUND,
|
||||
|
||||
// 403
|
||||
GuestAccessForbidden
|
||||
| GuestAccessForbidden
|
||||
| ThreepidAuthFailed
|
||||
| UserDeactivated
|
||||
| ThreepidDenied
|
||||
| WrongRoomKeysVersion {
|
||||
..
|
||||
}
|
||||
| Forbidden {
|
||||
..
|
||||
} => StatusCode::FORBIDDEN,
|
||||
| WrongRoomKeysVersion { .. }
|
||||
| Forbidden { .. } => StatusCode::FORBIDDEN,
|
||||
|
||||
// 401
|
||||
UnknownToken {
|
||||
..
|
||||
}
|
||||
| MissingToken
|
||||
| Unauthorized => StatusCode::UNAUTHORIZED,
|
||||
| UnknownToken { .. } | MissingToken | Unauthorized => StatusCode::UNAUTHORIZED,
|
||||
|
||||
// 400
|
||||
_ => StatusCode::BAD_REQUEST,
|
||||
| _ => StatusCode::BAD_REQUEST,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn ruma_error_message(error: &ruma::api::client::error::Error) -> String {
|
||||
if let ErrorBody::Standard {
|
||||
message,
|
||||
..
|
||||
} = &error.body
|
||||
{
|
||||
if let ErrorBody::Standard { message, .. } = &error.body {
|
||||
return message.to_string();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue