From 0c2f9707cd20bf9cf23bf8144ecbdb4f5d73c1cd Mon Sep 17 00:00:00 2001 From: jutty Date: Wed, 17 Dec 2025 02:22:17 -0300 Subject: [PATCH] Add a hardcoded template for early templating errors --- src/handlers/template.rs | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/handlers/template.rs b/src/handlers/template.rs index e819dc7..63ffe28 100644 --- a/src/handlers/template.rs +++ b/src/handlers/template.rs @@ -31,15 +31,16 @@ pub(in crate::handlers) fn render( context: &tera::Context, error_message: Option, ) -> (String, u16) { - // TODO just return an Option here + // TODO just return an Option/String> here let tera = match tera::Tera::new(concat!( env!("CARGO_MANIFEST_DIR"), "/templates/**/*" )) { Ok(t) => t, Err(e) => { - println!("Tera parsing error: {e:#?}"); - panic!("{e}") + let early_error_message = format!("{e:#?}"); + crate::dev::log(&by_filename, &early_error_message); + return (emergency_wrap(&e), 500) }, }; @@ -76,3 +77,33 @@ pub(in crate::handlers) fn render( }, } } + +fn emergency_wrap(message: &tera::Error) -> String { + format!(r#" + + + Pre-Templating Error + + + + + +

Early Pre-Templating Error

+

This normally indicates a malformed template.

+
+            {message}
+            
+

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

+ + + "#) +}