use crate::validate::ValidationError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("secret key not found: {key}")]
NotFound {
key: String,
},
#[error("provider unavailable: {provider}")]
ProviderUnavailable {
provider: String,
},
#[error("provider `{provider}` failed: {message}")]
Provider {
provider: String,
message: String,
},
#[error("configuration validation failed")]
Validation(#[from] ValidationError),
#[error("failed to deserialize configuration: {0}")]
Deserialize(String),
#[error("cache error: {0}")]
Cache(String),
#[error("crypto error: {0}")]
Crypto(String),
#[error("invalid configuration: {0}")]
InvalidConfig(String),
#[error("I/O error: {0}")]
Io(String),
#[error("internal error: {0}")]
Internal(String),
}
impl Error {
pub fn provider(provider: impl Into<String>, message: impl Into<String>) -> Self {
Self::Provider {
provider: provider.into(),
message: message.into(),
}
}
pub fn not_found(key: impl Into<String>) -> Self {
Self::NotFound { key: key.into() }
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::Io(value.to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display_does_not_include_secret_payloads() {
let err = Error::provider("aws", "access denied");
let s = err.to_string();
assert!(s.contains("aws"));
assert!(!s.contains("AKIA"));
}
}