{"record":{"id":"fc23f7e36e3f73cc","repo":"getzola/zola","slug":"no-templates-registered","errorCode":null,"errorMessage":"no templates registered","messagePattern":"no templates registered","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/templates/src/lib.rs","lineNumber":39,"sourceCode":"const BUILTIN_TEMPLATES: &[(&str, &str)] = &[\n    (\"__zola_builtins/404.html\", include_str!(\"builtins/404.html\")),\n    (\"__zola_builtins/atom.xml\", include_str!(\"builtins/atom.xml\")),\n    (\"__zola_builtins/rss.xml\", include_str!(\"builtins/rss.xml\")),\n    (\"__zola_builtins/sitemap.xml\", include_str!(\"builtins/sitemap.xml\")),\n    (\"__zola_builtins/robots.txt\", include_str!(\"builtins/robots.txt\")),\n    (\"__zola_builtins/split_sitemap_index.xml\", include_str!(\"builtins/split_sitemap_index.xml\")),\n    (\"__zola_builtins/anchor-link.html\", include_str!(\"builtins/anchor-link.html\")),\n    (\"__zola_builtins/summary-cutoff.html\", include_str!(\"builtins/summary-cutoff.html\")),\n    // This is not overridable by the user\n    (REDIRECT_TPL_NAME, include_str!(\"builtins/internal/alias.html\")),\n];\n\npub static ZOLA_TERA: LazyLock<Tera> = LazyLock::new(|| {\n    let mut tera = Tera::default();\n\n    // Only really needed for tests\n    tera.set_fallback_prefixes(vec![\"__zola_builtins/\".to_string()])\n        .expect(\"no templates registered\");\n\n    // tera-contrib stuff\n    tera.register_filter(\"base64_encode\", tera_contrib::base64::b64_encode);\n    tera.register_filter(\"base64_decode\", tera_contrib::base64::b64_decode);\n    tera.register_filter(\"regex_replace\", tera_contrib::regex::RegexReplace::default());\n    tera.register_filter(\"striptags\", tera_contrib::regex::striptags);\n    tera.register_filter(\"spaceless\", tera_contrib::regex::spaceless);\n    tera.register_filter(\"urlencode\", tera_contrib::urlencode::urlencode);\n    tera.register_filter(\"urlencode_strict\", tera_contrib::urlencode::urlencode_strict);\n    tera.register_filter(\"json_encode\", tera_contrib::json::json_encode);\n    tera.register_filter(\"filesizeformat\", tera_contrib::filesize_format::filesize_format);\n    tera.register_filter(\"format\", tera_contrib::format::format);\n    tera.register_filter(\"slugify\", tera_contrib::slug::slug);\n    tera.register_filter(\"date\", tera_contrib::dates::date);\n    tera.register_filter(\"shuffle\", tera_contrib::rand::shuffle);\n\n    tera.register_function(\"get_random\", tera_contrib::rand::get_random);\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/components/templates/src/lib.rs#L21-L57","documentation":"The global ZOLA_TERA LazyLock registers fallback prefixes on a default Tera instance with .expect(\"no templates registered\"). Tera's set_fallback_prefixes only fails when the instance has zero templates, but here it is called before registering any, relying on the fact this check passes for default instances; if the ordering or Tera version changes, first access panics.","triggerScenarios":"First access of ZOLA_TERA when set_fallback_prefixes is called on a Tera instance that contains no templates (Tera::default plus a Tera version whose fallback check requires templates).","commonSituations":"Using this static in unit tests after a Tera upgrade changed set_fallback_prefixes semantics; reordering the initialization code so it runs after an empty-instance check.","solutions":["Register at least one template (or add templates via add_raw_template) before calling set_fallback_prefixes","Replace expect with graceful handling that logs and continues without fallback prefixes","Pin/verify the tera dependency version matches the expected set_fallback_prefixes behavior"],"exampleFix":"// before\ntera.set_fallback_prefixes(vec![\"__zola_builtins/\".to_string()])\n    .expect(\"no templates registered\");\n// after\ntera.add_raw_template(\"__zola_builtins/anchor-link.html\", \"\").ok();\ntera.set_fallback_prefixes(vec![\"__zola_builtins/\".to_string()])\n    .expect(\"no templates registered\");","handlingStrategy":"validation","validationCode":"// ensure at least one template exists before set_fallback_prefixes\nif tera.templates.is_empty() {\n    tera.add_raw_template(\"__zola_builtins/placeholder.html\", \"\")\n        .expect(\"failed to register placeholder template\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = tera.set_fallback_prefixes(vec![\"__zola_builtins/\".to_string()]) {\n    eprintln!(\"warning: fallback prefixes not set: {}\", e);\n}","preventionTips":["Call set_fallback_prefixes only after registering templates","Pin the tera crate version; re-test ZOLA_TERA initialization on upgrades","Write an init test that touches ZOLA_TERA so LazyLock panics surface in CI"],"tags":["rust","tera","templates","panic","initialization"],"backgroundTag":"tera-no-templates-registered","analyzedSha":"61d30828217957120309db657950224edf9707e2","analyzedAt":"2026-09-03T14:39:09.727Z","contentChangedAt":"2026-09-03T14:39:09.727Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}