diff --git a/src/renderer/errors.rs b/src/renderer/errors.rs index 13f249e..6eb65ad 100644 --- a/src/renderer/errors.rs +++ b/src/renderer/errors.rs @@ -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)