use std::fmt;
use std::path::PathBuf;
#[derive(Debug)]
pub enum Error {
InvalidPost(String),
Io(PathBuf, std::io::Error),
UnknownCollection(String),
NotRegistered,
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidPost(message) => formatter.write_str(message),
Self::Io(path, error) => write!(formatter, "{}: {error}", path.display()),
Self::NotRegistered => formatter.write_str("Larablog is not registered: add the LarablogServiceProvider."),
Self::UnknownCollection(name) => write!(
formatter,
"There is no Larablog collection called `{name}` in the configuration."
),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(_, error) => Some(error),
_ => None,
}
}
}