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. +

+ + + "#) +}