1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug)]
8pub enum Error {
9 File(crate::file::Error),
11 DBus(crate::dbus::Error),
13}
14
15impl From<crate::file::Error> for Error {
16 fn from(e: crate::file::Error) -> Self {
17 Self::File(e)
18 }
19}
20
21impl From<crate::dbus::Error> for Error {
22 fn from(e: crate::dbus::Error) -> Self {
23 Self::DBus(e)
24 }
25}
26
27impl std::error::Error for Error {}
28
29impl fmt::Display for Error {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::File(e) => write!(f, "File backend error {e}"),
33 Self::DBus(e) => write!(f, "DBus error {e}"),
34 }
35 }
36}
37
38#[derive(Debug)]
40#[cfg(feature = "schema")]
41pub enum SchemaError {
42 MissingField(&'static str),
44
45 SchemaMismatch {
47 expected: String,
49 found: String,
51 },
52
53 InvalidValue {
55 field: &'static str,
57 value: String,
59 },
60}
61
62#[cfg(feature = "schema")]
63impl std::error::Error for SchemaError {}
64
65#[cfg(feature = "schema")]
66impl std::fmt::Display for SchemaError {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 match self {
69 Self::MissingField(field) => write!(f, "Missing required field: {field}"),
70 Self::SchemaMismatch { expected, found } => {
71 write!(f, "Schema mismatch: expected {expected}, found {found}")
72 }
73 Self::InvalidValue { field, value } => {
74 write!(f, "Invalid field value for {field}: {value}")
75 }
76 }
77 }
78}