Starting to create a WalkError type for walking that will not bubble up.

This commit is contained in:
Tom Alexander 2020-05-09 13:54:39 -04:00
parent 7d63d6ef7b
commit b20368c586
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -15,6 +15,17 @@ pub enum RenderError<'a> {
},
}
pub enum WalkError<'a> {
CantWalk {
segment: String,
elem: &'a dyn ContextElement,
},
NotFound {
path: &'a Vec<&'a str>,
breadcrumbs: Vec<&'a dyn ContextElement>,
},
}
#[derive(Clone)]
pub struct CompileError {
pub message: String,
@ -54,6 +65,38 @@ impl error::Error for RenderError<'_> {
}
}
impl fmt::Display for WalkError<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
WalkError::CantWalk { segment, elem } => {
write!(f, "Tried to walk to {} from {:?}", segment, elem)
}
WalkError::NotFound { path, breadcrumbs } => {
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
}
}
}
}
impl fmt::Debug for WalkError<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
WalkError::CantWalk { segment, elem } => {
write!(f, "Tried to walk to {} from {:?}", segment, elem)
}
WalkError::NotFound { path, breadcrumbs } => {
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
}
}
}
}
impl error::Error for WalkError<'_> {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}
}
impl fmt::Display for CompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Error compiling: {}", self.message)