Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

eidetica/user/
errors.rs

1//! Error types for the user system
2use thiserror::Error;
3
4use crate::entry::ID;
5
6#[derive(Error, Debug)]
7pub enum UserError {
8    #[error("User not found: {username}")]
9    UserNotFound { username: String },
10
11    #[error("Username already exists: {username}")]
12    UsernameAlreadyExists { username: String },
13
14    #[error(
15        "Multiple users detected with username '{username}' ({count} found). This indicates a race condition during user creation. Manual intervention required."
16    )]
17    DuplicateUsersDetected { username: String, count: usize },
18
19    #[error("Invalid password")]
20    InvalidPassword,
21
22    #[error("Password verification failed")]
23    PasswordVerificationFailed,
24
25    #[error("Key not found: {key_id}")]
26    KeyNotFound { key_id: String },
27
28    #[error("Key already exists: {key_id}")]
29    KeyAlreadyExists { key_id: String },
30
31    #[error("Encryption failed: {reason}")]
32    EncryptionFailed { reason: String },
33
34    #[error("Decryption failed: {reason}")]
35    DecryptionFailed { reason: String },
36
37    #[error("Operation requires admin permission")]
38    InsufficientPermissions,
39
40    #[error("No admin key available for database: {database_id}")]
41    NoAdminKey { database_id: String },
42
43    #[error("Database not tracked: {database_id}")]
44    DatabaseNotTracked { database_id: String },
45
46    #[error("User account disabled: {username}")]
47    UserDisabled { username: String },
48
49    #[error("Invalid salt length: expected {expected}, got {actual}")]
50    InvalidSaltLength { expected: usize, actual: usize },
51
52    #[error("Invalid nonce length: expected {expected}, got {actual}")]
53    InvalidNonceLength { expected: usize, actual: usize },
54
55    #[error("No key found for database: {database_id}")]
56    NoKeyForDatabase { database_id: ID },
57
58    #[error("No SigKey mapping found for key {key_id} in database {database_id}")]
59    NoSigKeyMapping { key_id: String, database_id: ID },
60
61    #[error("No SigKey found for key {key_id} in database {database_id}")]
62    NoSigKeyFound { key_id: String, database_id: ID },
63
64    #[error("Password required for operation: {operation}")]
65    PasswordRequired { operation: String },
66
67    #[error("Invalid key format: {reason}")]
68    InvalidKeyFormat { reason: String },
69
70    #[error("No keys available for user")]
71    NoKeysAvailable,
72}
73
74impl UserError {
75    /// Check if this error indicates a resource was not found.
76    pub fn is_not_found(&self) -> bool {
77        matches!(
78            self,
79            UserError::UserNotFound { .. }
80                | UserError::KeyNotFound { .. }
81                | UserError::DatabaseNotTracked { .. }
82        )
83    }
84}