1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum SecretError {
8 #[error("Invalid secret URI '{uri}': {reason}")]
10 InvalidUri { uri: String, reason: String },
11
12 #[error("Secret not found: {0}")]
14 NotFound(String),
15
16 #[error("Secret backend '{backend}' not available (feature not enabled)")]
18 BackendDisabled { backend: String },
19
20 #[error("{backend} error: {message}")]
22 BackendError { backend: String, message: String },
23
24 #[error("Access denied to secret: {0}")]
26 AccessDenied(String),
27
28 #[error("Failed to read file '{path}': {message}")]
30 FileError { path: PathBuf, message: String },
31
32 #[error("Environment variable '{var}' not set")]
34 EnvNotSet { var: String },
35}
36
37impl SecretError {
38 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 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 pub fn disabled(backend: impl Into<String>) -> Self {
56 Self::BackendDisabled {
57 backend: backend.into(),
58 }
59 }
60}