Skip to main content

envvault/
errors.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4/// All errors that can occur in EnvVault.
5#[derive(Debug, Error)]
6pub enum EnvVaultError {
7    // --- Crypto errors ---
8    #[error("Encryption failed: {0}")]
9    EncryptionFailed(String),
10
11    #[error("Decryption failed — wrong password or corrupted data")]
12    DecryptionFailed,
13
14    #[error("Key derivation failed: {0}")]
15    KeyDerivationFailed(String),
16
17    // --- Vault errors ---
18    #[error("Vault not found at {0}")]
19    VaultNotFound(PathBuf),
20
21    #[error("Vault already exists at {0}")]
22    VaultAlreadyExists(PathBuf),
23
24    #[error("Invalid vault format: {0}")]
25    InvalidVaultFormat(String),
26
27    #[error("HMAC verification failed — vault file may be tampered")]
28    HmacMismatch,
29
30    #[error("HMAC error: {0}")]
31    HmacError(String),
32
33    #[error("Secret '{0}' not found")]
34    SecretNotFound(String),
35
36    #[error("Secret '{0}' already exists (use `set` to update)")]
37    SecretAlreadyExists(String),
38
39    // --- Keyfile errors ---
40    #[error("Keyfile error: {0}")]
41    KeyfileError(String),
42
43    // --- Keyring errors ---
44    #[error("Keyring error: {0}")]
45    KeyringError(String),
46
47    // --- Config errors ---
48    #[error("Config file error: {0}")]
49    ConfigError(String),
50
51    // --- IO errors ---
52    #[error("IO error: {0}")]
53    Io(#[from] std::io::Error),
54
55    // --- Serialization errors ---
56    #[error("Serialization error: {0}")]
57    SerializationError(String),
58
59    // --- CLI errors ---
60    #[error("Command failed: {0}")]
61    CommandFailed(String),
62
63    #[error("User cancelled operation")]
64    UserCancelled,
65
66    #[error("Password mismatch — passwords do not match")]
67    PasswordMismatch,
68
69    #[error("Child process exited with code {0}")]
70    ChildProcessFailed(i32),
71
72    #[error("No command specified — use `envvault run -- <command>`")]
73    NoCommandSpecified,
74
75    // --- Phase 3 errors ---
76    #[error("Audit error: {0}")]
77    AuditError(String),
78
79    #[error("Editor error: {0}")]
80    EditorError(String),
81
82    #[error("Environment '{0}' not found — no vault file exists")]
83    EnvironmentNotFound(String),
84
85    // --- Phase 5 deferred errors ---
86    #[error("Clipboard error: {0}")]
87    ClipboardError(String),
88
89    #[error("Command not allowed: {0}")]
90    CommandNotAllowed(String),
91}
92
93/// Convenience type alias for EnvVault results.
94pub type Result<T> = std::result::Result<T, EnvVaultError>;