1use sos_core::{AuthenticationError, ErrorExt, VaultId};
3use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum Error {
9 #[error("could not find folder password for '{0}'")]
11 NoFolderPassword(VaultId),
12
13 #[error("database client is required")]
15 NoDatabase,
16
17 #[error("path {0} is not a file")]
19 NotFile(PathBuf),
20
21 #[error("no default folder")]
23 NoDefaultFolder,
24
25 #[error("no open folder")]
27 NoOpenFolder,
28
29 #[error("invalid PEM encoding")]
31 PemEncoding,
32
33 #[error("archive folder does not exist")]
35 NoArchive,
36
37 #[error("cannot unarchive, not archived")]
40 NotArchived,
41
42 #[error("cannot move to archive, already archived")]
45 AlreadyArchived,
46
47 #[cfg(feature = "contacts")]
49 #[error("no contacts folder")]
50 NoContactsFolder,
51
52 #[cfg(feature = "contacts")]
54 #[error("not a contact")]
55 NotContact,
56
57 #[cfg(feature = "clipboard")]
59 #[error("paths '{0:?}' did not match any nodes")]
60 JsonPathQueryEmpty(Vec<String>),
61
62 #[cfg(feature = "clipboard")]
63 #[error("clipboard is not configured")]
65 NoClipboard,
66
67 #[error(transparent)]
69 TryFromSlice(#[from] std::array::TryFromSliceError),
70
71 #[error(transparent)]
73 Core(#[from] sos_core::Error),
74
75 #[error(transparent)]
77 Authentication(#[from] sos_core::AuthenticationError),
78
79 #[cfg(feature = "search")]
80 #[error(transparent)]
82 Search(#[from] sos_search::Error),
83
84 #[error(transparent)]
86 Vault(#[from] sos_vault::Error),
87
88 #[error(transparent)]
90 Login(#[from] sos_login::Error),
91
92 #[error(transparent)]
94 Signer(#[from] sos_signer::Error),
95
96 #[error(transparent)]
98 Sync(#[from] sos_sync::Error),
99
100 #[error(transparent)]
102 Password(#[from] sos_password::Error),
103
104 #[error(transparent)]
106 BackendStorage(#[from] sos_backend::StorageError),
107
108 #[error(transparent)]
110 Storage(#[from] sos_client_storage::Error),
111
112 #[error(transparent)]
114 Backend(#[from] sos_backend::Error),
115
116 #[error(transparent)]
118 Database(#[from] sos_database::Error),
119
120 #[cfg(feature = "archive")]
122 #[error(transparent)]
123 Archive(#[from] sos_database::archive::Error),
124
125 #[error(transparent)]
127 Io(#[from] std::io::Error),
128
129 #[error(transparent)]
131 Json(#[from] serde_json::Error),
132
133 #[error(transparent)]
135 Uuid(#[from] uuid::Error),
136
137 #[error(transparent)]
139 Hex(#[from] hex::FromHexError),
140
141 #[cfg(feature = "contacts")]
143 #[error(transparent)]
144 Vcard(#[from] vcard4::Error),
145
146 #[cfg(feature = "clipboard")]
148 #[error(transparent)]
149 Clipboard(#[from] xclipboard::Error),
150
151 #[cfg(feature = "clipboard")]
153 #[error(transparent)]
154 TimeZone(#[from] time_tz::system::Error),
155
156 #[cfg(feature = "files")]
158 #[error(transparent)]
159 StripPrefix(#[from] std::path::StripPrefixError),
160
161 #[cfg(feature = "migrate")]
163 #[error(transparent)]
164 Migrate(#[from] sos_migrate::Error),
165
166 #[cfg(feature = "archive")]
168 #[error(transparent)]
169 BackupArchive(#[from] sos_filesystem::archive::Error),
170}
171
172impl ErrorExt for Error {
173 fn is_secret_not_found(&self) -> bool {
174 matches!(
175 self,
176 Error::Storage(sos_client_storage::Error::SecretNotFound(_))
177 )
178 }
179
180 fn is_forbidden(&self) -> bool {
181 matches!(
182 self,
183 Error::Authentication(AuthenticationError::NotAuthenticated)
184 | Error::Storage(sos_client_storage::Error::Authentication(
185 AuthenticationError::NotAuthenticated
186 ))
187 )
188 }
189
190 fn is_permission_denied(&self) -> bool {
191 matches!(
192 self,
193 Error::Vault(sos_vault::Error::Authentication(
194 AuthenticationError::PasswordVerification
195 ))
196 )
197 }
198}