Skip to main content

wrkflw_secrets/
error.rs

1use thiserror::Error;
2
3/// Result type for secret operations
4pub type SecretResult<T> = Result<T, SecretError>;
5
6/// Errors that can occur during secret operations
7#[derive(Error, Debug)]
8pub enum SecretError {
9    #[error("Secret not found: {name}")]
10    NotFound { name: String },
11
12    #[error("Secret provider '{provider}' not found")]
13    ProviderNotFound { provider: String },
14
15    #[error("Authentication failed for provider '{provider}': {reason}")]
16    AuthenticationFailed { provider: String, reason: String },
17
18    #[error("Network error accessing secret provider: {0}")]
19    NetworkError(String),
20
21    #[error("Invalid secret configuration: {0}")]
22    InvalidConfig(String),
23
24    #[error("Encryption error: {0}")]
25    EncryptionError(String),
26
27    #[error("IO error: {0}")]
28    IoError(#[from] std::io::Error),
29
30    #[error("JSON parsing error: {0}")]
31    JsonError(#[from] serde_json::Error),
32
33    #[error("YAML parsing error: {0}")]
34    YamlError(#[from] serde_yaml::Error),
35
36    #[error("Invalid secret value format: {0}")]
37    InvalidFormat(String),
38
39    #[error("Secret operation timeout")]
40    Timeout,
41
42    #[error("Permission denied accessing secret: {name}")]
43    PermissionDenied { name: String },
44
45    #[error("Internal error: {0}")]
46    Internal(String),
47
48    #[error("Invalid secret name: {reason}")]
49    InvalidSecretName { reason: String },
50
51    #[error("Secret value too large: {size} bytes (max: {max_size} bytes)")]
52    SecretTooLarge { size: usize, max_size: usize },
53
54    #[error("Rate limit exceeded: {0}")]
55    RateLimitExceeded(String),
56}
57
58impl SecretError {
59    /// Create a new NotFound error
60    pub fn not_found(name: impl Into<String>) -> Self {
61        Self::NotFound { name: name.into() }
62    }
63
64    /// Create a new ProviderNotFound error
65    pub fn provider_not_found(provider: impl Into<String>) -> Self {
66        Self::ProviderNotFound {
67            provider: provider.into(),
68        }
69    }
70
71    /// Create a new AuthenticationFailed error
72    pub fn auth_failed(provider: impl Into<String>, reason: impl Into<String>) -> Self {
73        Self::AuthenticationFailed {
74            provider: provider.into(),
75            reason: reason.into(),
76        }
77    }
78
79    /// Create a new InvalidConfig error
80    pub fn invalid_config(msg: impl Into<String>) -> Self {
81        Self::InvalidConfig(msg.into())
82    }
83
84    /// Create a new Internal error
85    pub fn internal(msg: impl Into<String>) -> Self {
86        Self::Internal(msg.into())
87    }
88}