anubis_vault/
error.rs

1//! Error types for Anubis Vault
2//!
3//! **The Judgement of Anubis** - When the scales tip, errors are revealed
4
5use thiserror::Error;
6
7/// Result type for Anubis Vault operations
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Error types for Anubis Vault
11///
12/// Like Anubis weighing hearts against the feather of Ma'at,
13/// these errors reveal when something is not in balance.
14#[derive(Error, Debug)]
15#[allow(missing_docs)]
16pub enum Error {
17    /// Cryptographic operation failed
18    #[error("Cryptographic error: {0}")]
19    Crypto(String),
20
21    /// Key derivation failed
22    #[error("Key derivation failed: {0}")]
23    KeyDerivation(String),
24
25    /// Encryption failed
26    #[error("Encryption failed: {0}")]
27    Encryption(String),
28
29    /// Decryption failed (Anubis rejects the unworthy)
30    #[error("𓁧 Anubis's seal cannot be broken: {0}")]
31    Decryption(String),
32
33    /// Vault operation failed
34    #[error("Vault error: {0}")]
35    Vault(String),
36
37    /// Secret not found
38    #[error("Secret not found: {0}")]
39    SecretNotFound(String),
40
41    /// Secret already exists
42    #[error("Secret already exists: {0}")]
43    SecretExists(String),
44
45    /// Vault not initialized (Anubis's chamber has not been consecrated)
46    #[error("🜏 Anubis's sacred chamber has not been initialized at {0}")]
47    VaultNotInitialized(String),
48
49    /// Vault already exists (Anubis's seal is already in place)
50    #[error("🜏 Anubis's vault already guards this path: {0}")]
51    VaultExists(String),
52
53    /// Invalid vault version (Ancient seal unrecognized)
54    #[error("🜏 Ancient seal version mismatch: found {got}, expected {expected}")]
55    InvalidVaultVersion { got: u32, expected: u32 },
56
57    /// I/O error
58    #[error("I/O error: {0}")]
59    Io(#[from] std::io::Error),
60
61    /// Serialization error
62    #[error("Serialization error: {0}")]
63    Serialization(String),
64
65    /// Deserialization error
66    #[error("Deserialization error: {0}")]
67    Deserialization(String),
68
69    /// Invalid input
70    #[error("Invalid input: {0}")]
71    InvalidInput(String),
72
73    /// Authentication failed (You are not worthy to pass)
74    #[error("𓋹 The guardian Anubis denies passage: {0}")]
75    AuthenticationFailed(String),
76
77    /// Permission denied (Only the worthy may enter)
78    #[error("𓋹 Only those chosen by Anubis may enter: {0}")]
79    PermissionDenied(String),
80
81    /// Generic error
82    #[error("{0}")]
83    Other(String),
84}
85
86impl From<argon2::Error> for Error {
87    fn from(err: argon2::Error) -> Self {
88        Error::KeyDerivation(err.to_string())
89    }
90}
91
92impl From<rmp_serde::encode::Error> for Error {
93    fn from(err: rmp_serde::encode::Error) -> Self {
94        Error::Serialization(err.to_string())
95    }
96}
97
98impl From<rmp_serde::decode::Error> for Error {
99    fn from(err: rmp_serde::decode::Error) -> Self {
100        Error::Deserialization(err.to_string())
101    }
102}
103
104impl From<chacha20poly1305::Error> for Error {
105    fn from(_: chacha20poly1305::Error) -> Self {
106        Error::AuthenticationFailed(
107            "Incorrect password or corrupted vault file. \
108             Anubis guards this chamber with unyielding resolve.".to_string()
109        )
110    }
111}
112
113impl From<serde_json::Error> for Error {
114    fn from(err: serde_json::Error) -> Self {
115        Error::Serialization(err.to_string())
116    }
117}