Adding NotFound error type.

This commit is contained in:
Tom Alexander 2020-05-04 23:36:13 -04:00
parent 033fc9de6b
commit 6bcc66dff5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 17 additions and 0 deletions

View File

@ -14,6 +14,10 @@ pub enum RenderError<'a> {
segment: String, segment: String,
elem: &'a dyn ContextElement, elem: &'a dyn ContextElement,
}, },
NotFound {
path: &'a Vec<&'a str>,
breadcrumbs: Vec<&'a dyn ContextElement>,
},
/// Attempting to render and unrenderable type (for example, an object without any filters) /// Attempting to render and unrenderable type (for example, an object without any filters)
CantRender { CantRender {
elem: &'a dyn ContextElement, elem: &'a dyn ContextElement,
@ -36,6 +40,9 @@ impl fmt::Display for RenderError<'_> {
write!(f, "Failed to walk to {} from {:?}", segment, elem) write!(f, "Failed to walk to {} from {:?}", segment, elem)
} }
RenderError::CantRender { elem } => write!(f, "Cant render {:?}", elem), RenderError::CantRender { elem } => write!(f, "Cant render {:?}", elem),
RenderError::NotFound { path, breadcrumbs } => {
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
}
} }
} }
} }
@ -51,6 +58,9 @@ impl fmt::Debug for RenderError<'_> {
write!(f, "Failed to walk to {} from {:?}", segment, elem) write!(f, "Failed to walk to {} from {:?}", segment, elem)
} }
RenderError::CantRender { elem } => write!(f, "Cant render {:?}", elem), RenderError::CantRender { elem } => write!(f, "Cant render {:?}", elem),
RenderError::NotFound { path, breadcrumbs } => {
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
}
} }
} }
} }

View File

@ -212,6 +212,13 @@ fn new_walk_path<'a>(
breadcrumbs: Vec<&'a dyn ContextElement>, breadcrumbs: Vec<&'a dyn ContextElement>,
path: &Vec<&str>, path: &Vec<&str>,
) -> Result<&'a dyn ContextElement, RenderError<'a>> { ) -> Result<&'a dyn ContextElement, RenderError<'a>> {
for context in breadcrumbs.iter().rev() {
match walk_path_from_single_level(*context, path)? {
WalkResult::NoWalk => {}
WalkResult::PartialWalk => {}
WalkResult::FullyWalked(_) => {}
}
}
Err(RenderError::Generic("temp".to_owned())) Err(RenderError::Generic("temp".to_owned()))
} }