use thiserror::Error;
#[derive(Debug, Error)]
pub enum TokenError {
#[error("Failed to read token file {path}: {source}")]
Io {
path: String,
source: std::io::Error,
},
#[error("Invalid token JSON in {path}: {source}")]
InvalidJson {
path: String,
source: serde_json::Error,
},
#[error("Invalid token file schema: {0}")]
Schema(String),
#[error(
"Token --{token} required by caller but not found in theme '{theme}'. Add --{token} to the theme or remove it from the required list."
)]
MissingToken {
theme: String,
token: String,
},
}
impl TokenError {
pub(crate) fn io(path: &std::path::Path, source: std::io::Error) -> Self {
Self::Io {
path: path.display().to_string(),
source,
}
}
pub(crate) fn json(path: &std::path::Path, source: serde_json::Error) -> Self {
Self::InvalidJson {
path: path.display().to_string(),
source,
}
}
}
pub type Result<T> = std::result::Result<T, TokenError>;