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
|
|
|
use toml;
|
|
|
|
|
2020-05-04 13:22:14 +02:00
|
|
|
use rsasl::SaslError;
|
2020-02-14 12:20:17 +01:00
|
|
|
|
2020-09-14 10:37:51 +02:00
|
|
|
// SpawnError is a somewhat ambigous name, `use as` to make it futures::SpawnError instead.
|
|
|
|
use futures::task as futures;
|
|
|
|
|
2020-09-15 11:38:15 +02:00
|
|
|
use paho_mqtt::errors as mqtt;
|
|
|
|
|
2020-02-14 12:20:17 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2020-02-16 16:02:03 +01:00
|
|
|
TomlDe(toml::de::Error),
|
|
|
|
TomlSer(toml::ser::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),
|
2020-09-10 10:39:46 +02:00
|
|
|
LMDB(lmdb::Error),
|
2020-09-10 11:50:19 +02:00
|
|
|
FlexbuffersDe(flexbuffers::DeserializationError),
|
|
|
|
FlexbuffersSer(flexbuffers::SerializationError),
|
2020-09-14 10:37:51 +02:00
|
|
|
FuturesSpawn(futures::SpawnError),
|
2020-09-15 11:38:15 +02:00
|
|
|
MQTT(mqtt::Error),
|
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::TomlDe(e) => {
|
|
|
|
write!(f, "TOML Decoding error: {}", e)
|
|
|
|
},
|
|
|
|
Error::TomlSer(e) => {
|
|
|
|
write!(f, "TOML Serialization error: {}", e)
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
|
|
|
Error::LMDB(e) => {
|
|
|
|
write!(f, "LMDB Error: {}", e)
|
|
|
|
},
|
2020-09-10 11:50:19 +02:00
|
|
|
Error::FlexbuffersDe(e) => {
|
|
|
|
write!(f, "Flexbuffers decoding error: {}", e)
|
|
|
|
},
|
|
|
|
Error::FlexbuffersSer(e) => {
|
|
|
|
write!(f, "Flexbuffers encoding error: {}", e)
|
|
|
|
},
|
2020-09-14 10:37:51 +02:00
|
|
|
Error::FuturesSpawn(e) => {
|
|
|
|
write!(f, "Future could not be spawned: {}", e)
|
|
|
|
},
|
2020-09-15 11:38:15 +02:00
|
|
|
Error::MQTT(e) => {
|
|
|
|
write!(f, "Paho MQTT encountered an error: {}", e)
|
|
|
|
},
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<toml::de::Error> for Error {
|
|
|
|
fn from(e: toml::de::Error) -> Error {
|
|
|
|
Error::TomlDe(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<toml::ser::Error> for Error {
|
|
|
|
fn from(e: toml::ser::Error) -> Error {
|
|
|
|
Error::TomlSer(e)
|
|
|
|
}
|
2020-02-14 12:20:17 +01:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 10:39:46 +02:00
|
|
|
impl From<lmdb::Error> for Error {
|
|
|
|
fn from(e: lmdb::Error) -> Error {
|
|
|
|
Error::LMDB(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:50:19 +02:00
|
|
|
impl From<flexbuffers::DeserializationError> for Error {
|
|
|
|
fn from(e: flexbuffers::DeserializationError) -> Error {
|
|
|
|
Error::FlexbuffersDe(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<flexbuffers::SerializationError> for Error {
|
|
|
|
fn from(e: flexbuffers::SerializationError) -> Error {
|
|
|
|
Error::FlexbuffersSer(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 10:37:51 +02:00
|
|
|
impl From<futures::SpawnError> for Error {
|
|
|
|
fn from(e: futures::SpawnError) -> Error {
|
|
|
|
Error::FuturesSpawn(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 11:38:15 +02:00
|
|
|
impl From<mqtt::Error> for Error {
|
|
|
|
fn from(e: mqtt::Error) -> Error {
|
|
|
|
Error::MQTT(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 10:37:51 +02:00
|
|
|
pub(crate) type Result<T> = std::result::Result<T, Error>;
|