{"record":{"id":"bafdb76c1c65bcbc","repo":"handlebars-lang/handlebars.js","slug":"unless-requires-exactly-one-argument","errorCode":null,"errorMessage":"#unless requires exactly one argument","messagePattern":"#unless requires exactly one argument","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"lib/handlebars/helpers/if.js","lineNumber":25,"sourceCode":"      throw new Exception('#if requires exactly one argument');\n    }\n    if (isFunction(conditional)) {\n      conditional = conditional.call(this);\n    }\n\n    // Default behavior is to render the positive path if the value is truthy and not empty.\n    // The `includeZero` option may be set to treat the conditional as purely not empty based on the\n    // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.\n    if ((!options.hash.includeZero && !conditional) || isEmpty(conditional)) {\n      return options.inverse(this);\n    } else {\n      return options.fn(this);\n    }\n  });\n\n  instance.registerHelper('unless', function (conditional, options) {\n    if (arguments.length != 2) {\n      throw new Exception('#unless requires exactly one argument');\n    }\n    return instance.helpers['if'].call(this, conditional, {\n      fn: options.inverse,\n      inverse: options.fn,\n      hash: options.hash,\n    });\n  });\n}\n","sourceCodeStart":7,"sourceCodeEnd":34,"githubUrl":"https://github.com/handlebars-lang/handlebars.js/blob/13a7a679910d2adbfe7f6fad61ce8f98426b0378/lib/handlebars/helpers/if.js#L7-L34","documentation":"Handlebars' #unless helper is the inverse of #if and likewise requires exactly one conditional argument plus the options object. The error is thrown at render time when #unless is given zero or multiple positional arguments, before delegating to the 'if' helper with swapped fn/inverse blocks.","triggerScenarios":"{{#unless}} with no argument; {{#unless a b}} with two positionals; calling instance.helpers.unless(value) directly without options; template assembly/parse quirks merging tokens so extra args end up on #unless.","commonSituations":"Copy-pasted templates where an argument was accidentally deleted or duplicated; upgrading or auto-formatting templates that mangled the mustache expression; direct helper invocation in tests missing the options object.","solutions":["Use exactly one argument: {{#unless value}}...{{/unless}}; remove extra positionals or convert them to hash pairs ({{#unless value key=val}}).","Add the missing conditional if #unless was left bare.","For compound conditions, wrap in a subexpression helper: {{#unless (or a b)}}.","When invoking programmatically, pass options: unless(value, {fn, inverse, hash})."],"exampleFix":"// before\n{{#unless}}...{{/unless}}\n// after\n{{#unless user.isBlocked}}...{{/unless}}","handlingStrategy":"validation","validationCode":"// Pre-render validation: #unless must take exactly one positional argument\nconst bad = /\\{\\{#unless\\s*(\\}|[^}]+\\s[^}\\s]+\\s+[^}\\s]+\\s*\\})/.test(source);\nif (bad) throw new Error('#unless must have exactly one positional argument');","typeGuard":"function hasExactlyOneArg(conditional, options) {\n  return arguments.length === 2 && options && typeof options === 'object';\n}","tryCatchPattern":"try {\n  return template(data);\n} catch (e) {\n  if (e.message.includes('#unless requires exactly one argument')) {\n    console.error('Template #unless has zero or multiple args; fix the template expression');\n  }\n  throw e;\n}","preventionTips":["Write {{#unless value}} with exactly one positional argument","Convert extra arguments to hash pairs (key=value)","Use subexpression helpers like (or a b) for compound conditions","Lint templates for malformed #unless expressions","Render every template once in CI tests to catch these at build time"],"tags":["handlebars","unless-helper","wrong-argument-count"],"backgroundTag":"wrong-argument-count","analyzedSha":"13a7a679910d2adbfe7f6fad61ce8f98426b0378","analyzedAt":"2026-09-02T20:25:07.518Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}