{"record":{"id":"9e9602d3397cbcd9","repo":"tauri-apps/tauri","slug":"failed-to-setup-custom-handlebar-template","errorCode":null,"errorMessage":"Failed to setup custom handlebar template","messagePattern":"Failed to setup custom handlebar template","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-bundler/src/bundle/windows/msi/mod.rs","lineNumber":738,"sourceCode":"  if let Some(file_associations) = settings.file_associations() {\n    data.insert(\"file_associations\", to_json(file_associations));\n  }\n\n  if let Some(protocols) = settings.deep_link_protocols() {\n    let schemes = protocols\n      .iter()\n      .flat_map(|p| &p.schemes)\n      .collect::<Vec<_>>();\n    if !schemes.is_empty() {\n      data.insert(\"deep_link_protocols\", to_json(schemes));\n    }\n  }\n\n  if let Some(path) = custom_template_path {\n    handlebars\n      .register_template_string(\"main.wxs\", fs::read_to_string(path)?)\n      .map_err(|e| e.to_string())\n      .expect(\"Failed to setup custom handlebar template\");\n  } else {\n    handlebars\n      .register_template_string(\"main.wxs\", include_str!(\"./main.wxs\"))\n      .map_err(|e| e.to_string())\n      .expect(\"Failed to setup handlebar template\");\n  }\n\n  if enable_elevated_update_task {\n    data.insert(\n      \"msiexec_args\",\n      to_json(\n        settings\n          .updater()\n          .map(|updater| updater.msiexec_args)\n          .map(|args| args.join(\" \"))\n          .unwrap_or_else(|| \"/passive\".to_string()),\n      ),\n    );","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-bundler/src/bundle/windows/msi/mod.rs#L720-L756","documentation":"When bundle.windows.wix.template points at a custom WiX template, the MSI bundler registers the file's contents as a Handlebars template. Registration parses the template, and a Handlebars syntax error (unbalanced {{ }}, malformed block) turns into this expect and aborts the run. A missing or unreadable template file instead surfaces earlier as the propagated fs error, not this panic.","triggerScenarios":"tauri build --bundles msi with a custom template containing invalid Handlebars syntax — unclosed {{#if}}/{{/if}}, stray {{, or expressions that do not compile against the bundler's handlebars version.","commonSituations":"Copying the stock main.wxs and hand-editing it; using WiX preprocessor syntax inside Handlebars expressions; carrying a template forward across tauri versions whose expected helpers/placeholders changed.","solutions":["Parse-check the template with Handlebars before bundling (e.g. node -e with handlebars.compile) and fix the reported syntax error","Diff the custom template against the stock main.wxs of the tauri version you build with, and re-apply edits incrementally","Temporarily remove the wix.template config to confirm the built-in path bundles fine, isolating the fault to the custom file","Regenerate the custom template from the current tauri release's main.wxs rather than carrying old edits forward"],"exampleFix":"<!-- custom template — before -->\n<?if {{{{build_arch}}}} = \"x64\" ?>  <!-- stray/unclosed Handlebars expressions -->\n\n<!-- after -->\n{{#if (eq build_arch \"x64\")}}\n  <Condition Message=\"x64 only\">VersionNT64</Condition>\n{{/if}}","handlingStrategy":"validation","validationCode":"# preflight: parse-check the custom WiX template with Handlebars before tauri build\nnode -e 'const h=require(\"handlebars\");const s=require(\"fs\").readFileSync(process.argv[1],\"utf8\");try{h.compile(s);console.log(\"template OK\")}catch(e){console.error(e.message);process.exit(1)}' custom.wxs","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a Handlebars compile check on custom templates in CI before tauri build","Base custom templates on the stock main.wxs of the exact tauri version in use","Keep {{#if}}/{{/if}} blocks balanced; re-check after every edit"],"tags":["windows","msi","wix","handlebars","template","tauri-bundler"],"backgroundTag":"template-parse-error","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}