Improve minijinja and tera template error logs.

This commit is contained in:
Michael Melanson 2024-04-28 19:50:17 -04:00 committed by Sergio Benitez
parent 35a100fdec
commit 347d9da663
2 changed files with 19 additions and 8 deletions

View File

@ -43,13 +43,25 @@ impl Engine for Environment<'static> {
}
fn render<C: Serialize>(&self, name: &str, context: C) -> Option<String> {
let Ok(template) = self.get_template(name) else {
error_!("Minijinja template '{name}' was not found.");
return None;
let template = match self.get_template(name) {
Ok(template) => template,
Err(e) => {
error_!("Minijinja template '{name}' error: {e}");
return None;
}
};
template.render(context)
.map_err(|e| error_!("Minijinja: {}", e))
.ok()
match template.render(context) {
Ok(result) => Some(result),
Err(e) => {
error_!("Error rendering Minijinja template '{name}': {e}");
let mut error = &e as &dyn std::error::Error;
while let Some(source) = error.source() {
error_!("caused by: {source}");
error = source;
}
None
}
}
}
}

View File

@ -48,8 +48,7 @@ impl Engine for Tera {
match Tera::render(self, name, &tera_ctx) {
Ok(string) => Some(string),
Err(e) => {
error_!("Error rendering Tera template '{}'.", name);
error_!("Error rendering Tera template '{name}': {e}");
let mut error = Some(&e as &dyn Error);
while let Some(err) = error {
error_!("{}", err);