pub type Result<T> = core::result::Result<T, Error>;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("I/O Error: {0}")]
Io(#[from] std::io::Error),
#[error("Bluetooth: {0}")]
Bt(#[from] btleplug::Error),
#[cfg(feature = "metrics")]
#[error("Prometheus error: {0}")]
Prometheus(#[from] prometheus::Error),
#[error("UTF-8 error")]
Utf8(#[from] core::str::Utf8Error),
#[error("Timeout")]
Timeout,
#[error("Not found")]
NotFound,
#[error("Invalid checksum")]
BadCrc,
#[error("Invalid record type")]
BadRecordType,
#[error("Connection lost")]
LostConnection,
#[error("Not enough data")]
NotEnoughData,
#[error("Not supported")]
NotSupported,
#[error("Unknown hostname")]
UnknownHostname,
#[cfg(feature = "json")]
#[error("JSON format error: {0}")]
JsonEnc(#[from] serde_json::Error),
#[cfg(feature = "yaml")]
#[error("YAML format error: {0}")]
YamlEnc(#[from] serde_yaml::Error),
#[cfg(feature = "toml")]
#[error("TOML format error: {0}")]
TomlEnc(#[from] serde_toml::ser::Error),
}
impl From<tokio::time::error::Elapsed> for Error {
fn from(_: tokio::time::error::Elapsed) -> Self {
Self::Timeout
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(error: std::string::FromUtf8Error) -> Self {
error.utf8_error().into()
}
}