1#[derive(zbus::DBusError, Debug)]
4#[zbus(prefix = "org.freedesktop.Secret.Error")]
5pub enum ServiceError {
6 #[zbus(error)]
7 ZBus(zbus::Error),
9 IsLocked(String),
11 NoSession(String),
13 NoSuchObject(String),
15}
16
17#[derive(Debug)]
19pub enum Error {
20 ZBus(zbus::Error),
22 Service(ServiceError),
24 Deleted,
26 Dismissed,
28 NotFound(String),
30 IO(std::io::Error),
32 Crypto(crate::crypto::Error),
34 #[cfg(feature = "schema")]
36 Schema(crate::SchemaError),
37}
38
39impl From<zbus::Error> for Error {
40 fn from(e: zbus::Error) -> Self {
41 Self::ZBus(e)
42 }
43}
44
45impl From<zbus::fdo::Error> for Error {
46 fn from(e: zbus::fdo::Error) -> Self {
47 Self::ZBus(zbus::Error::FDO(Box::new(e)))
48 }
49}
50
51impl From<zbus::zvariant::Error> for Error {
52 fn from(e: zbus::zvariant::Error) -> Self {
53 Self::ZBus(zbus::Error::Variant(e))
54 }
55}
56
57impl From<ServiceError> for Error {
58 fn from(e: ServiceError) -> Self {
59 Self::Service(e)
60 }
61}
62
63impl From<std::io::Error> for Error {
64 fn from(e: std::io::Error) -> Self {
65 Self::IO(e)
66 }
67}
68
69impl From<crate::crypto::Error> for Error {
70 fn from(value: crate::crypto::Error) -> Self {
71 Self::Crypto(value)
72 }
73}
74
75#[cfg(feature = "schema")]
76impl From<crate::SchemaError> for Error {
77 fn from(value: crate::SchemaError) -> Self {
78 Self::Schema(value)
79 }
80}
81
82impl std::error::Error for Error {}
83
84impl std::fmt::Display for Error {
85 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86 match self {
87 Self::ZBus(err) => write!(f, "zbus error {err}"),
88 Self::Service(err) => write!(f, "service error {err}"),
89 Self::IO(err) => write!(f, "IO error {err}"),
90 Self::Deleted => write!(f, "Item/Collection was deleted, can no longer be used"),
91 Self::NotFound(name) => write!(f, "The collection '{name}' doesn't exists"),
92 Self::Dismissed => write!(f, "Prompt was dismissed"),
93 Self::Crypto(e) => write!(f, "Failed to do a cryptography operation, {e}"),
94 #[cfg(feature = "schema")]
95 Self::Schema(e) => write!(f, "Schema error: {e}"),
96 }
97 }
98}