use std::sync::Arc;
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Clone, Error, Diagnostic)]
#[non_exhaustive]
pub enum CredentialError {
#[error("credential not found: {name}")]
#[diagnostic(code(rtb::credentials::not_found))]
NotFound {
name: String,
},
#[error("literal credential is refused in CI environments")]
#[diagnostic(
code(rtb::credentials::literal_refused),
help("set CI=false locally, or move the secret to a keychain/env var")
)]
LiteralRefusedInCi,
#[error("keychain backend error: {0}")]
#[diagnostic(code(rtb::credentials::keychain))]
Keychain(String),
#[error("this credential store is read-only")]
#[diagnostic(code(rtb::credentials::read_only))]
ReadOnly,
#[error("I/O error: {0}")]
#[diagnostic(code(rtb::credentials::io))]
Io(Arc<std::io::Error>),
}
impl From<std::io::Error> for CredentialError {
fn from(e: std::io::Error) -> Self {
Self::Io(Arc::new(e))
}
}