diff --git a/src/router/handlers/template.rs b/src/router/handlers/template.rs index 1a5f520..72c1fb2 100644 --- a/src/router/handlers/template.rs +++ b/src/router/handlers/template.rs @@ -53,7 +53,7 @@ pub(in crate::router::handlers) fn render( let tera = match tera::Tera::new("./templates/**/*") { Ok(t) => t, Err(e) => { - return (emergency_wrap(&e), 500); + return (emergency_wrap(&e, "Failed instantiating template engine"), 500); }, }; @@ -66,15 +66,8 @@ pub(in crate::router::handlers) fn render( let mut error_context = tera::Context::default(); let mut out_error_message = match error_message { - Some(s) => format!( - "Template render failed.\n\ - User message: {s}, - Engine message:\n
{e:#?}"
- ),
- None => format!(
- "Template render failed.\n\
- Engine message:\n{e:#?}"
- ),
+ Some(s) => emergency_wrap(&e, &s),
+ None => emergency_wrap(&e, "Template render failed."),
};
if log::env_level() >= VERBOSE {
@@ -100,36 +93,42 @@ pub(in crate::router::handlers) fn render(
}
}
-fn emergency_wrap(error: &tera::Error) -> String {
+fn emergency_wrap(error: &tera::Error, message: &str) -> String {
log!(ERROR, "{error:#?}");
+
+ let message_element = format!("{message}
"); + format!( - r#" - - -This normally indicates a malformed template.
-
- {error:#?}
-
- - If you haven't modified templates, plese consider - reporting it. -
- - - "# + "\n\ + \n\ + \n\ +\n\
+ {error:#?}\n\
+ \n\
+ This normally indicates a malformed or missing template.
\n\ +\n\ + If you haven't modified templates, please consider\n\ + reporting it.\n\ +
\n\ + \n\ + \n\ + " ) } @@ -229,7 +228,7 @@ mod tests { fn emergency_wrap_custom_message() { let payload = "JLaTtsnd2IFukIOvqFNymeuiaS6nMaUc"; let error = tera::Error::msg(payload); - let html = emergency_wrap(&error); + let html = emergency_wrap(&error, ""); assert!(html.matches(payload).count() == 1); } }