{"record":{"id":"be67ded5a564f493","repo":"tauri-apps/tauri","slug":"failed-to-setup-handlebar-template","errorCode":null,"errorMessage":"Failed to setup handlebar template","messagePattern":"Failed to setup handlebar template","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-bundler/src/bundle/windows/msi/mod.rs","lineNumber":747,"sourceCode":"    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    );\n\n    // Create the update task XML\n    let skip_uac_task = Handlebars::new();\n    let xml = include_str!(\"./update-task.xml\");\n    let update_content = skip_uac_task.render_template(xml, &data)?;","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-bundler/src/bundle/windows/msi/mod.rs#L729-L765","documentation":"During the WiX MSI build, tauri-bundler registers the main.wxs Handlebars template. When a custom template path is configured, the template string is compiled with register_template_string; if Handlebars fails to parse/compile it, the crate panics via .expect(\"Failed to setup handlebar template\") (the custom-template branch panics with \"Failed to setup custom handlebar template\"). This aborts bundling immediately because an unparseable template means no installer can be generated.","triggerScenarios":"Calling bundle_project with bundle.windows.wix.template set to a custom .wxs file whose content fails Handlebars compilation (malformed Handlebars syntax such as unclosed {{#if}} blocks, bad helper usage, or invalid characters). The map_err to String then expect turns the compile error into a panic.","commonSituations":"Users copy an old main.wxs from a previous tauri version into their Tauri config; template variables/helpers changed between tauri-bundler releases, so the custom template no longer compiles. Also hand-edited templates with mismatched {{/each}} or {{#if}} tags, or a template saved with the wrong encoding.","solutions":["Open the custom .wxs template and fix the Handlebars syntax error (check every {{#if}}/{{#each}} has a matching closing tag).","Test the template against the built-in one: temporarily remove bundle.windows.wix.template from tauri.conf.json to confirm the stock template builds.","Update your custom template to match the current tauri-bundler main.wxs (copy from the tauri-bundler version you use and re-apply your edits).","Verify the template file is valid UTF-8 and not truncated."],"exampleFix":"// before (tauri.conf.json)\n\"wix\": { \"template\": \"installer/main.wxs\" }  // template has unclosed {{#if}}\n\n// after\n// fix installer/main.wxs:\n// {{#if product_version}} ... {{/if}}   <- ensure every block is closed","handlingStrategy":"validation","validationCode":"// validate custom wix template before bundling\nlet tpl = std::fs::read_to_string(\"installer/main.wxs\")?;\nhandlebars::Handlebars::new().register_template_string(\"main.wxs\", tpl)\n  .map_err(|e| anyhow!(\"invalid wix template: {}\", e))?;","typeGuard":"fn is_valid_template(h: &handlebars::Handlebars, name: &str, src: &str) -> bool {\n  h.register_template_string(name, src).is_ok()\n}","tryCatchPattern":"// in Rust the panic aborts the process; run bundling in a subprocess and surface stderr,\n// or pre-validate the template as above before calling bundle_project.","preventionTips":["Re-derive custom templates from the main.wxs of your exact tauri-bundler version after every upgrade","Lint Handlebars blocks ({{#if}}/{{#each}} closings) before committing the template","Keep template edits small and test a full bundle build in CI"],"tags":["wix","msi","handlebars","template","windows"],"backgroundTag":"handlebars-template-error","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}