use thiserror::Error;
#[derive(Debug, Error)]
pub enum VaultError {
#[error("passphrase incorrecta")]
WrongPassphrase,
#[error("vault_meta corrupto e irrecuperable")]
VaultMetaCorrupt,
#[error("secreto no encontrado: {0}")]
SecretNotFound(String),
#[error("error de cripto: {0}")]
Crypto(String),
#[error("error de almacenamiento: {0}")]
Storage(String),
}
#[cfg(test)]
mod tests {
use super::VaultError;
#[test]
fn test_wrong_passphrase_display_is_user_facing_and_leaks_nothing() {
let e = VaultError::WrongPassphrase;
assert_eq!(e.to_string(), "passphrase incorrecta");
}
#[test]
fn test_vault_meta_corrupt_is_distinct_variant() {
let e = VaultError::VaultMetaCorrupt;
assert!(e.to_string().to_lowercase().contains("corrupt"));
}
#[test]
fn test_secret_not_found_includes_name_only() {
let e = VaultError::SecretNotFound("OPENAI_API_KEY".to_string());
let msg = e.to_string();
assert!(msg.contains("OPENAI_API_KEY"));
}
}