1use thiserror::Error;
9
10#[derive(Debug, Error)]
12pub enum SafeError {
13 #[error("vault not found: {path}")]
14 VaultNotFound { path: String },
15
16 #[error("vault already exists: {path}")]
17 VaultAlreadyExists { path: String },
18
19 #[error("secret not found: {key}")]
20 SecretNotFound { key: String },
21
22 #[error("secret already exists: {key}")]
23 SecretAlreadyExists { key: String },
24
25 #[error("profile not found: {name}")]
26 ProfileNotFound { name: String },
27
28 #[error("decryption failed — wrong password or corrupted vault")]
29 DecryptionFailed,
30
31 #[error("crypto error: {context}")]
32 Crypto { context: String },
33
34 #[error("invalid vault: {reason}")]
35 InvalidVault { reason: String },
36
37 #[error("import parse error in {file}: {reason}")]
38 ImportParse { file: String, reason: String },
39
40 #[error("no snapshots available to restore profile '{profile}'")]
41 NoSnapshotAvailable { profile: String },
42
43 #[error("snapshot not found: {path}")]
44 SnapshotNotFound { path: String },
45
46 #[error("vault schema migration failed: {reason}")]
47 MigrationFailed { reason: String },
48
49 #[error("vault is corrupted and could not be auto-healed: {reason}")]
50 VaultCorrupted { reason: String },
51
52 #[error(
61 "stale biometric credential: the stored credential no longer matches the vault (password \
62 was rotated or biometric enrollment changed). Run `tsafe biometric re-enroll` to \
63 restore password-free unlock."
64 )]
65 StaleBiometricCredential,
66
67 #[error("Windows Hello verification was canceled by the user")]
71 BiometricCanceled,
72
73 #[error("Windows Hello verification failed: {0}")]
76 BiometricFailed(String),
77
78 #[error("io error: {0}")]
79 Io(#[from] std::io::Error),
80
81 #[error("serialization error: {0}")]
82 Serialization(#[from] serde_json::Error),
83}
84
85pub type SafeResult<T> = Result<T, SafeError>;