sos_client_storage/
error.rs1use sos_core::{AuthenticationError, ErrorExt, SecretId, VaultId};
2use std::path::PathBuf;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum Error {
8 #[error("no vault is available, vault must be open")]
11 NoOpenVault,
12
13 #[error("path {0} is not a directory")]
15 NotDirectory(PathBuf),
16
17 #[error("not a file secret")]
19 NotFileContent,
20
21 #[error("could not determine cache directory")]
23 NoCache,
24
25 #[error("could not find folder password for '{0}'")]
28 NoFolderPassword(VaultId),
29
30 #[error("no file password")]
32 NoFilePassword,
33
34 #[error(r#"secret "{0}" not found"#)]
36 SecretNotFound(SecretId),
37
38 #[error("could not find create vault event")]
42 NoVaultEvent,
43
44 #[error(transparent)]
46 TryFromSlice(#[from] std::array::TryFromSliceError),
47
48 #[error(transparent)]
50 FileSystem(#[from] sos_filesystem::Error),
51
52 #[error(transparent)]
54 Vault(#[from] sos_vault::Error),
55
56 #[error(transparent)]
58 Login(#[from] sos_login::Error),
59
60 #[error(transparent)]
62 Core(#[from] sos_core::Error),
63
64 #[error(transparent)]
66 Authentication(#[from] sos_core::AuthenticationError),
67
68 #[cfg(feature = "search")]
69 #[error(transparent)]
71 Search(#[from] sos_search::Error),
72
73 #[error(transparent)]
75 Password(#[from] sos_password::Error),
76
77 #[error(transparent)]
79 Sync(#[from] sos_sync::Error),
80
81 #[error(transparent)]
83 BackendStorage(#[from] sos_backend::StorageError),
84
85 #[error(transparent)]
87 Backend(#[from] sos_backend::Error),
88
89 #[error(transparent)]
91 Database(#[from] sos_database::Error),
92
93 #[error(transparent)]
95 Io(#[from] std::io::Error),
96
97 #[cfg(feature = "files")]
99 #[error(transparent)]
100 AgeEncrypt(#[from] age::EncryptError),
101
102 #[cfg(feature = "files")]
104 #[error(transparent)]
105 AgeDecrypt(#[from] age::DecryptError),
106}
107
108impl ErrorExt for Error {
109 fn is_secret_not_found(&self) -> bool {
110 matches!(self, Error::SecretNotFound(_))
111 }
112
113 fn is_forbidden(&self) -> bool {
114 matches!(
115 self,
116 Error::Authentication(AuthenticationError::NotAuthenticated)
117 )
118 }
119
120 fn is_permission_denied(&self) -> bool {
121 matches!(
122 self,
123 Error::Vault(sos_vault::Error::Authentication(
124 AuthenticationError::PasswordVerification
125 ))
126 )
127 }
128}