mirror of https://github.com/rwf2/Rocket.git
Improve minijinja and tera template error logs.
This commit is contained in:
parent
35a100fdec
commit
347d9da663
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue