1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use sos_core::{AuthenticationError, ErrorExt, SecretId, VaultId};
use std::path::PathBuf;
use thiserror::Error;
/// Errors generated by the client storage library.
#[derive(Debug, Error)]
pub enum Error {
/// Error generated attempting to make changes to the current
/// vault but no vault is open.
#[error("no vault is available, vault must be open")]
NoOpenVault,
/// Error generated when a directory is expected.
#[error("path {0} is not a directory")]
NotDirectory(PathBuf),
/// Error generated when a file secret is expected.
#[error("not a file secret")]
NotFileContent,
/// Error generated if we could not determine a cache directory.
#[error("could not determine cache directory")]
NoCache,
/// Error generated when a folder password in the identity
/// vault could not be located.
#[error("could not find folder password for '{0}'")]
NoFolderPassword(VaultId),
/// Error generated when a file encryption password is required.
#[error("no file password")]
NoFilePassword,
/// Error generated when a secret could not be found.
#[error(r#"secret "{0}" not found"#)]
SecretNotFound(SecretId),
/// Error generated if we could not find a create vault event
/// in a collection of event records or as the first event in
/// a folder event log.
#[error("could not find create vault event")]
NoVaultEvent,
/// Error generated converting to fixed length slice.
#[error(transparent)]
TryFromSlice(#[from] std::array::TryFromSliceError),
/// Error generated by the filesystem library.
#[error(transparent)]
FileSystem(#[from] sos_filesystem::Error),
/// Error generated by the vault library.
#[error(transparent)]
Vault(#[from] sos_vault::Error),
/// Error generated by the login library.
#[error(transparent)]
Login(#[from] sos_login::Error),
/// Errors generated by the core library.
#[error(transparent)]
Core(#[from] sos_core::Error),
/// Authentication errors.
#[error(transparent)]
Authentication(#[from] sos_core::AuthenticationError),
#[cfg(feature = "search")]
/// Errors generated by the search library.
#[error(transparent)]
Search(#[from] sos_search::Error),
/// Errors generated by the password library.
#[error(transparent)]
Password(#[from] sos_password::Error),
/// Errors generated by the sync library.
#[error(transparent)]
Sync(#[from] sos_sync::Error),
/// Errors generated by the backend storage.
#[error(transparent)]
BackendStorage(#[from] sos_backend::StorageError),
/// Errors generated by the backend library.
#[error(transparent)]
Backend(#[from] sos_backend::Error),
/// Errors generated by the database library.
#[error(transparent)]
Database(#[from] sos_database::Error),
/// Errors generated by the IO module.
#[error(transparent)]
Io(#[from] std::io::Error),
/// Error generated by the AGE library when encrypting.
#[cfg(feature = "files")]
#[error(transparent)]
AgeEncrypt(#[from] age::EncryptError),
/// Error generated by the AGE library when decrypting.
#[cfg(feature = "files")]
#[error(transparent)]
AgeDecrypt(#[from] age::DecryptError),
}
impl ErrorExt for Error {
fn is_secret_not_found(&self) -> bool {
matches!(self, Error::SecretNotFound(_))
}
fn is_forbidden(&self) -> bool {
matches!(
self,
Error::Authentication(AuthenticationError::NotAuthenticated)
)
}
fn is_permission_denied(&self) -> bool {
matches!(
self,
Error::Vault(sos_vault::Error::Authentication(
AuthenticationError::PasswordVerification
))
)
}
}