use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("yaml error: {0}")]
Yaml(#[from] serde_yaml::Error),
#[error("validation failed:\n{0}")]
Validation(String),
}
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValidationError {
pub page_id: String,
pub field: String,
pub message: String,
}
impl ValidationError {
pub fn new(
page_id: impl Into<String>,
field: impl Into<String>,
message: impl Into<String>,
) -> Self {
Self {
page_id: page_id.into(),
field: field.into(),
message: message.into(),
}
}
}
impl std::fmt::Display for ValidationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "page `{}` field `{}`: {}", self.page_id, self.field, self.message)
}
}