Skip to content

Commit

Permalink
feat: provide a reason() function to access template reason
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Sep 4, 2022
1 parent 0ab7108 commit 4883c24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ impl TemplateError {
self.template_name = Some(name);
self
}

/// Get underlying reason for the error
pub fn reason(&self) -> &TemplateErrorReason {
self.reason.as_ref()
}
}

impl From<(IOError, String)> for TemplateError {
Expand Down
4 changes: 2 additions & 2 deletions src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ mod test {

let terr = Template::compile(source).unwrap_err();

assert!(matches!(*terr.reason, TemplateErrorReason::InvalidSyntax));
assert!(matches!(terr.reason(), TemplateErrorReason::InvalidSyntax));
assert_eq!(terr.line_no.unwrap(), 4);
assert_eq!(terr.column_no.unwrap(), 5);
}
Expand Down Expand Up @@ -1127,7 +1127,7 @@ mod test {
for s in sources.iter() {
let result = Template::compile(s.to_owned());
assert!(matches!(
*result.unwrap_err().reason,
*result.unwrap_err().reason(),
TemplateErrorReason::InvalidSyntax
));
}
Expand Down

0 comments on commit 4883c24

Please sign in to comment.