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> {
|
fn render<C: Serialize>(&self, name: &str, context: C) -> Option<String> {
|
||||||
let Ok(template) = self.get_template(name) else {
|
let template = match self.get_template(name) {
|
||||||
error_!("Minijinja template '{name}' was not found.");
|
Ok(template) => template,
|
||||||
|
Err(e) => {
|
||||||
|
error_!("Minijinja template '{name}' error: {e}");
|
||||||
return None;
|
return None;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template.render(context)
|
match template.render(context) {
|
||||||
.map_err(|e| error_!("Minijinja: {}", e))
|
Ok(result) => Some(result),
|
||||||
.ok()
|
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) {
|
match Tera::render(self, name, &tera_ctx) {
|
||||||
Ok(string) => Some(string),
|
Ok(string) => Some(string),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error_!("Error rendering Tera template '{}'.", name);
|
error_!("Error rendering Tera template '{name}': {e}");
|
||||||
|
|
||||||
let mut error = Some(&e as &dyn Error);
|
let mut error = Some(&e as &dyn Error);
|
||||||
while let Some(err) = error {
|
while let Some(err) = error {
|
||||||
error_!("{}", err);
|
error_!("{}", err);
|
||||||
|
|
Loading…
Reference in New Issue