use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValidationError {
message: String,
}
impl ValidationError {
pub(crate) fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
}
impl fmt::Display for ValidationError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.message)
}
}
impl std::error::Error for ValidationError {}
pub(crate) fn invalid(message: impl Into<String>) -> anyhow::Error {
ValidationError::new(message).into()
}
pub(crate) fn invalid_with_source<E>(source: E, message: impl Into<String>) -> anyhow::Error
where
E: std::error::Error + Send + Sync + 'static,
{
anyhow::Error::new(source).context(ValidationError::new(message))
}