2020-02-14 12:20:17 +01:00
|
|
|
use std::io;
|
2020-05-04 13:22:14 +02:00
|
|
|
use std::fmt;
|
2020-02-16 16:02:03 +01:00
|
|
|
|
2020-05-04 13:22:14 +02:00
|
|
|
use rsasl::SaslError;
|
2020-02-14 12:20:17 +01:00
|
|
|
|
2021-10-20 18:37:50 +02:00
|
|
|
use crate::db::DBError;
|
2020-09-15 11:38:15 +02:00
|
|
|
|
2021-10-06 13:53:14 +02:00
|
|
|
//FIXME use crate::network;
|
2020-12-07 14:39:35 +01:00
|
|
|
|
2020-02-14 12:20:17 +01:00
|
|
|
#[derive(Debug)]
|
2021-10-28 01:10:35 +02:00
|
|
|
/// Shared error type
|
2020-02-14 12:20:17 +01:00
|
|
|
pub enum Error {
|
2020-05-04 13:22:14 +02:00
|
|
|
SASL(SaslError),
|
2020-02-16 16:02:03 +01:00
|
|
|
IO(io::Error),
|
2020-02-18 16:55:19 +01:00
|
|
|
Boxed(Box<dyn std::error::Error>),
|
2020-05-11 18:21:45 +02:00
|
|
|
Capnp(capnp::Error),
|
2021-10-20 18:37:50 +02:00
|
|
|
DB(DBError),
|
2020-11-30 14:08:03 +01:00
|
|
|
Denied,
|
2020-02-16 16:02:03 +01:00
|
|
|
}
|
|
|
|
|
2020-05-04 13:22:14 +02:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
Error::SASL(e) => {
|
|
|
|
write!(f, "SASL Error: {}", e)
|
|
|
|
},
|
|
|
|
Error::IO(e) => {
|
|
|
|
write!(f, "IO Error: {}", e)
|
|
|
|
},
|
|
|
|
Error::Boxed(e) => {
|
|
|
|
write!(f, "{}", e)
|
2020-09-10 10:44:16 +02:00
|
|
|
},
|
2020-05-11 18:21:45 +02:00
|
|
|
Error::Capnp(e) => {
|
|
|
|
write!(f, "Cap'n Proto Error: {}", e)
|
2020-09-10 10:44:16 +02:00
|
|
|
},
|
2021-10-20 18:37:50 +02:00
|
|
|
Error::DB(e) => {
|
|
|
|
write!(f, "DB Error: {:?}", e)
|
2020-09-10 10:44:16 +02:00
|
|
|
},
|
2020-11-30 14:08:03 +01:00
|
|
|
Error::Denied => {
|
|
|
|
write!(f, "You do not have the permission required to do that.")
|
|
|
|
}
|
2020-05-04 13:22:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SaslError> for Error {
|
|
|
|
fn from(e: SaslError) -> Error {
|
2020-02-16 16:02:03 +01:00
|
|
|
Error::SASL(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(e: io::Error) -> Error {
|
|
|
|
Error::IO(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 16:55:19 +01:00
|
|
|
impl From<Box<dyn std::error::Error>> for Error {
|
|
|
|
fn from(e: Box<dyn std::error::Error>) -> Error {
|
|
|
|
Error::Boxed(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 18:21:45 +02:00
|
|
|
impl From<capnp::Error> for Error {
|
|
|
|
fn from(e: capnp::Error) -> Error {
|
|
|
|
Error::Capnp(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 18:37:50 +02:00
|
|
|
impl From<DBError> for Error {
|
|
|
|
fn from(e: DBError) -> Error {
|
|
|
|
Error::DB(e)
|
2020-09-10 10:39:46 +02:00
|
|
|
}
|
2021-10-28 01:10:35 +02:00
|
|
|
}
|