use transparent thiserror attribute; cleanup error variants
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
f69f4c479c
commit
bac795de5f
1 changed files with 58 additions and 60 deletions
|
@ -16,86 +16,84 @@ pub enum Error {
|
||||||
Panic(&'static str, Box<dyn Any + Send + 'static>),
|
Panic(&'static str, Box<dyn Any + Send + 'static>),
|
||||||
|
|
||||||
// std
|
// std
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
Fmt(#[from] fmt::Error),
|
Fmt(#[from] fmt::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
FromUtf8(#[from] std::string::FromUtf8Error),
|
||||||
#[error("I/O error: {0}")]
|
#[error("I/O error: {0}")]
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
Utf8Error(#[from] std::str::Utf8Error),
|
ParseFloat(#[from] std::num::ParseFloatError),
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
FromUtf8Error(#[from] std::string::FromUtf8Error),
|
ParseInt(#[from] std::num::ParseIntError),
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
TryFromSliceError(#[from] std::array::TryFromSliceError),
|
TryFromInt(#[from] std::num::TryFromIntError),
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
TryFromIntError(#[from] std::num::TryFromIntError),
|
TryFromSlice(#[from] std::array::TryFromSliceError),
|
||||||
#[error("{0}")]
|
#[error(transparent)]
|
||||||
ParseIntError(#[from] std::num::ParseIntError),
|
Utf8(#[from] std::str::Utf8Error),
|
||||||
#[error("{0}")]
|
|
||||||
ParseFloatError(#[from] std::num::ParseFloatError),
|
|
||||||
|
|
||||||
// third-party
|
// third-party
|
||||||
|
#[error(transparent)]
|
||||||
|
CargoToml(#[from] cargo_toml::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
Clap(#[from] clap::error::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
Extension(#[from] axum::extract::rejection::ExtensionRejection),
|
||||||
|
#[error(transparent)]
|
||||||
|
Figment(#[from] figment::error::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
Http(#[from] http::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
HttpHeader(#[from] http::header::InvalidHeaderValue),
|
||||||
|
#[error("Image error: {0}")]
|
||||||
|
Image(#[from] image::error::ImageError),
|
||||||
#[error("Join error: {0}")]
|
#[error("Join error: {0}")]
|
||||||
JoinError(#[from] tokio::task::JoinError),
|
JoinError(#[from] tokio::task::JoinError),
|
||||||
|
#[error(transparent)]
|
||||||
|
Path(#[from] axum::extract::rejection::PathRejection),
|
||||||
#[error("Regex error: {0}")]
|
#[error("Regex error: {0}")]
|
||||||
Regex(#[from] regex::Error),
|
Regex(#[from] regex::Error),
|
||||||
|
#[error("Request error: {0}")]
|
||||||
|
Reqwest(#[from] reqwest::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
TomlDe(#[from] toml::de::Error),
|
||||||
|
#[error(transparent)]
|
||||||
|
TomlSer(#[from] toml::ser::Error),
|
||||||
#[error("Tracing filter error: {0}")]
|
#[error("Tracing filter error: {0}")]
|
||||||
TracingFilter(#[from] tracing_subscriber::filter::ParseError),
|
TracingFilter(#[from] tracing_subscriber::filter::ParseError),
|
||||||
#[error("Tracing reload error: {0}")]
|
#[error("Tracing reload error: {0}")]
|
||||||
TracingReload(#[from] tracing_subscriber::reload::Error),
|
TracingReload(#[from] tracing_subscriber::reload::Error),
|
||||||
#[error("Image error: {0}")]
|
|
||||||
Image(#[from] image::error::ImageError),
|
|
||||||
#[error("Request error: {0}")]
|
|
||||||
Reqwest(#[from] reqwest::Error),
|
|
||||||
#[error("{0}")]
|
|
||||||
Extension(#[from] axum::extract::rejection::ExtensionRejection),
|
|
||||||
#[error("{0}")]
|
|
||||||
Path(#[from] axum::extract::rejection::PathRejection),
|
|
||||||
#[error("{0}")]
|
|
||||||
Http(#[from] http::Error),
|
|
||||||
#[error("{0}")]
|
|
||||||
HttpHeader(#[from] http::header::InvalidHeaderValue),
|
|
||||||
#[error("{0}")]
|
|
||||||
CargoToml(#[from] cargo_toml::Error),
|
|
||||||
#[error("{0}")]
|
|
||||||
FigmentError(#[from] figment::error::Error),
|
|
||||||
#[error("{0}")]
|
|
||||||
TomlSerError(#[from] toml::ser::Error),
|
|
||||||
#[error("{0}")]
|
|
||||||
TomlDeError(#[from] toml::de::Error),
|
|
||||||
#[error("{0}")]
|
|
||||||
Clap(#[from] clap::error::Error),
|
|
||||||
|
|
||||||
// ruma
|
// ruma/conduwuit
|
||||||
#[error("{0}")]
|
|
||||||
IntoHttpError(#[from] ruma::api::error::IntoHttpError),
|
|
||||||
#[error("{0}")]
|
|
||||||
RumaError(#[from] ruma::api::client::error::Error),
|
|
||||||
#[error("uiaa")]
|
|
||||||
Uiaa(ruma::api::client::uiaa::UiaaInfo),
|
|
||||||
#[error("{0}")]
|
|
||||||
Mxid(#[from] ruma::IdParseError),
|
|
||||||
#[error("{0}: {1}")]
|
|
||||||
BadRequest(ruma::api::client::error::ErrorKind, &'static str), //TODO: remove
|
|
||||||
#[error("{0}: {1}")]
|
|
||||||
Request(ruma::api::client::error::ErrorKind, Cow<'static, str>, http::StatusCode),
|
|
||||||
#[error("from {0}: {1}")]
|
|
||||||
Redaction(ruma::OwnedServerName, ruma::canonical_json::RedactionError),
|
|
||||||
#[error("Remote server {0} responded with: {1}")]
|
|
||||||
Federation(ruma::OwnedServerName, ruma::api::client::error::Error),
|
|
||||||
#[error("{0} in {1}")]
|
|
||||||
InconsistentRoomState(&'static str, ruma::OwnedRoomId),
|
|
||||||
|
|
||||||
// conduwuit
|
|
||||||
#[error("Arithmetic operation failed: {0}")]
|
#[error("Arithmetic operation failed: {0}")]
|
||||||
Arithmetic(Cow<'static, str>),
|
Arithmetic(Cow<'static, str>),
|
||||||
|
#[error("{0}: {1}")]
|
||||||
|
BadRequest(ruma::api::client::error::ErrorKind, &'static str), //TODO: remove
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
BadServerResponse(Cow<'static, str>),
|
BadServerResponse(Cow<'static, str>),
|
||||||
#[error("There was a problem with the '{0}' directive in your configuration: {1}")]
|
#[error("There was a problem with the '{0}' directive in your configuration: {1}")]
|
||||||
Config(&'static str, Cow<'static, str>),
|
Config(&'static str, Cow<'static, str>),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
Database(Cow<'static, str>),
|
|
||||||
#[error("{0}")]
|
|
||||||
Conflict(&'static str), // This is only needed for when a room alias already exists
|
Conflict(&'static str), // This is only needed for when a room alias already exists
|
||||||
|
#[error("{0}")]
|
||||||
|
Database(Cow<'static, str>),
|
||||||
|
#[error("Remote server {0} responded with: {1}")]
|
||||||
|
Federation(ruma::OwnedServerName, ruma::api::client::error::Error),
|
||||||
|
#[error("{0} in {1}")]
|
||||||
|
InconsistentRoomState(&'static str, ruma::OwnedRoomId),
|
||||||
|
#[error(transparent)]
|
||||||
|
IntoHttp(#[from] ruma::api::error::IntoHttpError),
|
||||||
|
#[error(transparent)]
|
||||||
|
Mxid(#[from] ruma::IdParseError),
|
||||||
|
#[error("from {0}: {1}")]
|
||||||
|
Redaction(ruma::OwnedServerName, ruma::canonical_json::RedactionError),
|
||||||
|
#[error("{0}: {1}")]
|
||||||
|
Request(ruma::api::client::error::ErrorKind, Cow<'static, str>, http::StatusCode),
|
||||||
|
#[error(transparent)]
|
||||||
|
Ruma(#[from] ruma::api::client::error::Error),
|
||||||
|
#[error("uiaa")]
|
||||||
|
Uiaa(ruma::api::client::uiaa::UiaaInfo),
|
||||||
|
|
||||||
// unique / untyped
|
// unique / untyped
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
@ -117,7 +115,7 @@ impl Error {
|
||||||
pub fn message(&self) -> String {
|
pub fn message(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::Federation(ref origin, ref error) => format!("Answer from {origin}: {error}"),
|
Self::Federation(ref origin, ref error) => format!("Answer from {origin}: {error}"),
|
||||||
Self::RumaError(ref error) => response::ruma_error_message(error),
|
Self::Ruma(ref error) => response::ruma_error_message(error),
|
||||||
_ => format!("{self}"),
|
_ => format!("{self}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +134,7 @@ impl Error {
|
||||||
|
|
||||||
pub fn status_code(&self) -> http::StatusCode {
|
pub fn status_code(&self) -> http::StatusCode {
|
||||||
match self {
|
match self {
|
||||||
Self::Federation(_, ref error) | Self::RumaError(ref error) => error.status_code,
|
Self::Federation(_, ref error) | Self::Ruma(ref error) => error.status_code,
|
||||||
Self::Request(ref kind, _, code) => response::status_code(kind, *code),
|
Self::Request(ref kind, _, code) => response::status_code(kind, *code),
|
||||||
Self::BadRequest(ref kind, ..) => response::bad_request_code(kind),
|
Self::BadRequest(ref kind, ..) => response::bad_request_code(kind),
|
||||||
Self::Conflict(_) => http::StatusCode::CONFLICT,
|
Self::Conflict(_) => http::StatusCode::CONFLICT,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue