{"record":{"id":"a96a1843fc3568f1","repo":"tauri-apps/tauri","slug":"failed-to-setup-custom-handlebar-template-a96a18","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/nsis/mod.rs","lineNumber":632,"sourceCode":"    let mut output = String::new();\n    for c in s.chars() {\n      match c {\n        '\\\"' => output.push_str(\"$\\\\\\\"\"),\n        '$' => output.push_str(\"$$\"),\n        '`' => output.push_str(\"$\\\\`\"),\n        '\\n' => output.push_str(\"$\\\\n\"),\n        '\\t' => output.push_str(\"$\\\\t\"),\n        '\\r' => output.push_str(\"$\\\\r\"),\n        _ => output.push(c),\n      }\n    }\n    output\n  });\n  if let Some(path) = custom_template_path {\n    handlebars\n      .register_template_string(\"installer.nsi\", std::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(\"installer.nsi\", include_str!(\"./installer.nsi\"))\n      .map_err(|e| e.to_string())\n      .expect(\"Failed to setup handlebar template\");\n  }\n\n  write_utf8_with_bom(\n    output_path.join(\"FileAssociation.nsh\"),\n    include_bytes!(\"./FileAssociation.nsh\"),\n  )?;\n  write_utf8_with_bom(output_path.join(\"utils.nsh\"), include_bytes!(\"./utils.nsh\"))?;\n\n  let installer_nsi_path = output_path.join(\"installer.nsi\");\n  write_utf8_with_bom(\n    &installer_nsi_path,\n    handlebars.render(\"installer.nsi\", &data)?,\n  )?;","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs#L614-L650","documentation":"When you configure a custom NSIS template, the bundler reads your template file and registers it with the handlebars registry. register_template_string fails if handlebars cannot parse the template (unclosed {{ }}, unknown block syntax, invalid partial), and this expect() panics with 'Failed to setup custom handlebar template'. It means your custom installer template is syntactically invalid as a handlebars template.","triggerScenarios":"`tauri build --bundles nsis` (Windows) with bundle > windows > nsis > installerHooks / custom template path pointing at a .nsi file containing malformed handlebars syntax — e.g. {{#if x}} without {{/if}}, a stray {{, or template comments that break parsing. The registration at crates/tauri-bundler/src/bundle/windows/nsis/mod.rs:632 maps the parse error to a string and immediately expects success.","commonSituations":"Editing the copied stock installer.nsi template and breaking a block; upgrading Tauri versions where the expected template variables/blocks changed while your old custom template keeps deprecated syntax; using NSIS `${...}` constructs adjacent to handlebars braces that confuse the parser.","solutions":["Open your custom template and find the handlebars syntax error — run `npx handlebars <file>` or an editor with handlebars highlighting to locate unbalanced {{ }} blocks.","Diff your custom template against the stock installer.nsi of the exact tauri-bundler version you use (crates/tauri-bundler/src/bundle/windows/nsis/installer.nsi) and re-apply your changes on top of the current stock template.","Verify every {{#if}}/{{#each}} has a matching close tag and that variables you reference exist in the data object.","Rebuild with `tauri build --bundles nsis`."],"exampleFix":"; before — unclosed block in custom installer.nsi\n{{#if installMode}}\n  !insertmacro REINSTALL_MODE\n\n; after\n{{#if installMode}}\n  !insertmacro REINSTALL_MODE\n{{/if}}","handlingStrategy":"validation","validationCode":"// CI step: verify the custom NSIS template parses as handlebars before tauri build\n// npx --yes handlebars-cli parse installer.nsi  (non-zero exit = syntax error)\nfn check_template_balance(src: &str) -> bool {\n    let mut depth = 0i32;\n    let mut rest = src;\n    while let Some(start) = rest.find(\"{{#\") {\n        depth += 1;\n        rest = &rest[start + 3..];\n    }\n    depth >= 0\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep custom NSIS templates in version control and lint them in CI before release builds.","After upgrading Tauri, re-diff your custom template against the new stock installer.nsi and port your changes.","Ensure every {{#if}}/{{#each}} block has a matching {{/if}}/{{/each}}; test template edits locally with --bundles nsis before pushing."],"tags":["tauri","nsis","handlebars","template","bundler","windows","panic"],"backgroundTag":"template-parse-error","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}