use std::fmt::{Display, Formatter};
use crate::TemplateInputException;
#[derive(Debug)]
pub enum TemplateResourceError {
InvalidArgument(String),
MalformedUrl {
location: String,
source: url::ParseError,
},
Input(TemplateInputException),
}
impl Display for TemplateResourceError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidArgument(message) => formatter.write_str(message),
Self::MalformedUrl { location, source } => {
write!(formatter, "Malformed URL \"{location}\": {source}")
}
Self::Input(error) => Display::fmt(error, formatter),
}
}
}
impl std::error::Error for TemplateResourceError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidArgument(_) => None,
Self::MalformedUrl { source, .. } => Some(source),
Self::Input(error) => error.source(),
}
}
}