use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
File(crate::file::Error),
DBus(crate::dbus::Error),
}
impl From<crate::file::Error> for Error {
fn from(e: crate::file::Error) -> Self {
Self::File(e)
}
}
impl From<crate::dbus::Error> for Error {
fn from(e: crate::dbus::Error) -> Self {
Self::DBus(e)
}
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::File(e) => write!(f, "File backend error {e}"),
Self::DBus(e) => write!(f, "DBus error {e}"),
}
}
}
#[derive(Debug)]
#[cfg(feature = "schema")]
pub enum SchemaError {
MissingField(&'static str),
SchemaMismatch {
expected: String,
found: String,
},
InvalidValue {
field: &'static str,
value: String,
},
}
#[cfg(feature = "schema")]
impl std::error::Error for SchemaError {}
#[cfg(feature = "schema")]
impl std::fmt::Display for SchemaError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingField(field) => write!(f, "Missing required field: {field}"),
Self::SchemaMismatch { expected, found } => {
write!(f, "Schema mismatch: expected {expected}, found {found}")
}
Self::InvalidValue { field, value } => {
write!(f, "Invalid field value for {field}: {value}")
}
}
}
}