97 lines
2.4 KiB
Rust
97 lines
2.4 KiB
Rust
#[derive(Debug)]
|
|
pub enum Error {
|
|
Generic(String),
|
|
Sqlx(sqlx::Error),
|
|
TokioJoin(tokio::task::JoinError),
|
|
Io(std::io::Error),
|
|
Rustls(rustls::Error),
|
|
Rcgen(rcgen::Error),
|
|
WebPki(rustls::client::VerifierBuilderError),
|
|
}
|
|
|
|
impl std::fmt::Display for Error {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Error::Generic(err) => {
|
|
write!(f, "generic error: {err}")
|
|
}
|
|
Error::Sqlx(err) => {
|
|
write!(f, "sqlx error: {err:?}")
|
|
}
|
|
Error::TokioJoin(err) => {
|
|
write!(f, "tokio join error: {err:?}")
|
|
}
|
|
Error::Io(err) => {
|
|
write!(f, "io error: {err:?}")
|
|
}
|
|
Error::Rustls(err) => {
|
|
write!(f, "rustls error: {err:?}")
|
|
}
|
|
Error::Rcgen(err) => {
|
|
write!(f, "rcgen error: {err:?}")
|
|
}
|
|
Error::WebPki(err) => {
|
|
write!(f, "webpki error: {err:?}")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for Error {
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
match self {
|
|
Error::Sqlx(err) => Some(err),
|
|
Error::TokioJoin(err) => Some(err),
|
|
Error::Io(err) => Some(err),
|
|
Error::Rustls(err) => Some(err),
|
|
Error::Rcgen(err) => Some(err),
|
|
Error::WebPki(err) => Some(err),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::str::FromStr for Error {
|
|
type Err = Self;
|
|
|
|
fn from_str(err: &str) -> Result<Self, Self::Err> {
|
|
Ok(Self::Generic(err.to_string()))
|
|
}
|
|
}
|
|
|
|
impl From<sqlx::Error> for Error {
|
|
fn from(err: sqlx::Error) -> Self {
|
|
Self::Sqlx(err)
|
|
}
|
|
}
|
|
|
|
impl From<tokio::task::JoinError> for Error {
|
|
fn from(err: tokio::task::JoinError) -> Self {
|
|
Self::TokioJoin(err)
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for Error {
|
|
fn from(err: std::io::Error) -> Self {
|
|
Self::Io(err)
|
|
}
|
|
}
|
|
|
|
impl From<rustls::Error> for Error {
|
|
fn from(err: rustls::Error) -> Self {
|
|
Self::Rustls(err)
|
|
}
|
|
}
|
|
|
|
impl From<rcgen::Error> for Error {
|
|
fn from(err: rcgen::Error) -> Self {
|
|
Self::Rcgen(err)
|
|
}
|
|
}
|
|
|
|
impl From<rustls::client::VerifierBuilderError> for Error {
|
|
fn from(err: rustls::client::VerifierBuilderError) -> Self {
|
|
Self::WebPki(err)
|
|
}
|
|
}
|