Skip to content

Commit

Permalink
feat: make MissingVariable accepting optional string
Browse files Browse the repository at this point in the history
  • Loading branch information
linw1995 committed Nov 21, 2022
1 parent b309b58 commit 832679d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl From<TemplateError> for RenderError {
#[derive(Debug, Error)]
pub enum RenderErrorReason {
#[error("missing variable path {0:?}")]
MissingVariable(String),
MissingVariable(Option<String>),
}

impl From<RenderErrorReason> for RenderError {
Expand Down Expand Up @@ -119,10 +119,7 @@ impl RenderError {
}

pub fn strict_error(path: Option<&String>) -> RenderError {
match path {
Some(path) => RenderErrorReason::MissingVariable(path.to_owned()).into(),
None => RenderError::new("Value is missing in strict mode"),
}
RenderErrorReason::MissingVariable(path.map(|p| p.to_owned())).into()
}

pub fn from_error<E>(error_info: &str, cause: E) -> RenderError
Expand Down
4 changes: 2 additions & 2 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ mod test {
.source()
.and_then(|e| e.downcast_ref::<RenderErrorReason>())
.and_then(|e| match e {
RenderErrorReason::MissingVariable(path) => Some(path),
RenderErrorReason::MissingVariable(path) => path.to_owned(),
})
.unwrap(),
"the_key_never_exists"
Expand All @@ -1013,7 +1013,7 @@ mod test {
.source()
.and_then(|e| e.downcast_ref::<RenderErrorReason>())
.and_then(|e| match e {
RenderErrorReason::MissingVariable(path) => Some(path),
RenderErrorReason::MissingVariable(path) => path.to_owned(),
})
.unwrap(),
"this.[3]"
Expand Down

0 comments on commit 832679d

Please sign in to comment.