use std::io; use std::fmt; use rsasl::SaslError; use crate::db::DBError; //FIXME use crate::network; #[derive(Debug)] /// Shared error type pub enum Error { SASL(SaslError), IO(io::Error), Boxed(Box), Capnp(capnp::Error), DB(DBError), Denied, } 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) }, Error::Capnp(e) => { write!(f, "Cap'n Proto Error: {}", e) }, Error::DB(e) => { write!(f, "DB Error: {:?}", e) }, Error::Denied => { write!(f, "You do not have the permission required to do that.") } } } } impl From for Error { fn from(e: SaslError) -> Error { Error::SASL(e) } } impl From for Error { fn from(e: io::Error) -> Error { Error::IO(e) } } impl From> for Error { fn from(e: Box) -> Error { Error::Boxed(e) } } impl From for Error { fn from(e: capnp::Error) -> Error { Error::Capnp(e) } } impl From for Error { fn from(e: DBError) -> Error { Error::DB(e) } }