siphon_secrets/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5/// Errors that can occur during secret resolution
6#[derive(Debug, Error)]
7pub enum SecretError {
8    /// Invalid URI format
9    #[error("Invalid secret URI '{uri}': {reason}")]
10    InvalidUri { uri: String, reason: String },
11
12    /// Secret not found in backend
13    #[error("Secret not found: {0}")]
14    NotFound(String),
15
16    /// Backend feature not compiled in
17    #[error("Secret backend '{backend}' not available (feature not enabled)")]
18    BackendDisabled { backend: String },
19
20    /// Backend runtime error
21    #[error("{backend} error: {message}")]
22    BackendError { backend: String, message: String },
23
24    /// Permission/access denied
25    #[error("Access denied to secret: {0}")]
26    AccessDenied(String),
27
28    /// File IO error
29    #[error("Failed to read file '{path}': {message}")]
30    FileError { path: PathBuf, message: String },
31
32    /// Environment variable error
33    #[error("Environment variable '{var}' not set")]
34    EnvNotSet { var: String },
35}
36
37impl SecretError {
38    /// Create an invalid URI error
39    pub fn invalid_uri(uri: impl Into<String>, reason: impl Into<String>) -> Self {
40        Self::InvalidUri {
41            uri: uri.into(),
42            reason: reason.into(),
43        }
44    }
45
46    /// Create a backend error
47    pub fn backend(backend: impl Into<String>, message: impl Into<String>) -> Self {
48        Self::BackendError {
49            backend: backend.into(),
50            message: message.into(),
51        }
52    }
53
54    /// Create a backend disabled error
55    pub fn disabled(backend: impl Into<String>) -> Self {
56        Self::BackendDisabled {
57            backend: backend.into(),
58        }
59    }
60}