From 56a9541fdf6cee656137a5af8dd64df3bba34f36 Mon Sep 17 00:00:00 2001 From: jutty Date: Sun, 8 Mar 2026 02:53:04 -0300 Subject: [PATCH] Use emergency_wrap in more cases --- src/router/handlers/template.rs | 77 ++++++++++++++++----------------- 1 file changed, 38 insertions(+), 39 deletions(-) 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#" - - - Pre-Templating Error - - - - - -

Early Pre-Templating Error

-

This normally indicates a malformed template.

-
-            {error:#?}
-            
-

- If you haven't modified templates, plese consider - reporting it. -

- - - "# + "\n\ + \n\ + \n\ + en Pre-Templating Error\n + \n\ + \n\ + \n\ + \n\ + \n\ +

en Early Pre-Templating Error

\n\ + {message_element}\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); } }