{"record":{"id":"e34288024dfbcccb","repo":"gchq/CyberChef","slug":"e","errorCode":null,"errorMessage":"${e}","messagePattern":"\\$\\{e\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/Template.mjs","lineNumber":48,"sourceCode":"                name: \"Template definition (.handlebars)\",\n                type: \"text\",\n                value: \"\"\n            }\n        ];\n    }\n\n    /**\n     * @param {JSON} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const [templateStr] = args;\n        try {\n            const template = Handlebars.compile(templateStr);\n            return template(input);\n        } catch (e) {\n            throw new OperationError(e);\n        }\n    }\n}\n\nexport default Template;\n","sourceCodeStart":30,"sourceCodeEnd":54,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/Template.mjs#L30-L54","documentation":"The Template operation compiles a Handlebars template string and renders it against the JSON input. Any error raised by Handlebars.compile() or by invoking the compiled template — syntax errors, unknown helpers, type errors during rendering — is caught and rethrown as an OperationError whose message is the original error.","triggerScenarios":"A malformed Handlebars template (unbalanced braces, unclosed block like {{#each}} without {{/each}}, or an unterminated expression); referencing a helper that is not registered; or rendering a template whose partial/helper expects a type the JSON input does not provide.","commonSituations":"Authoring a template with a typo in block syntax; using a custom helper that Handlebars does not ship; passing non-object JSON that the template indexes into.","solutions":["Validate the template syntax in an external Handlebars playground before pasting it in.","Ensure every block helper {{#x}} has a matching {{/x}}.","Remove references to helpers that are not part of Handlebars core.","Feed valid JSON input that matches the fields the template references."],"exampleFix":"// before: template = \"{{#each items}}{{name}}{{/loop}}\"  (mismatched block name)\n// after:  template = \"{{#each items}}{{name}}{{/each}}\"","handlingStrategy":"try-catch","validationCode":"let compiled;\ntry { compiled = Handlebars.compile(templateStr); }\ncatch (e) { throw new Error(`Template syntax invalid: ${e.message}`); }\nreturn compiled(jsonInput);","typeGuard":"function isCompilableTemplate(tpl) {\n  try { Handlebars.precompile(tpl); return true; } catch { return false; }\n}","tryCatchPattern":"try { chef.Template(jsonInput, [templateStr]); }\ncatch (e) { if (/Parse error|Expecting/.test(e.message)) { /* fix template syntax */ } else throw e; }","preventionTips":["Precompile templates in isolation to surface syntax errors.","Match every {{#block}} with its {{/block}}.","Only reference Handlebars core helpers unless custom ones are registered."],"tags":["handlebars","template","syntax","json"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}