{"record":{"id":"d277fed3237dc1f3","repo":"emberjs/ember.js","slug":"and-expects-at-least-two-arguments-but-received","errorCode":null,"errorMessage":"`and` expects at least two arguments, but received ${positional.length}.","messagePattern":"`and` expects at least two arguments, but received (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/@glimmer/runtime/lib/helpers/and.ts","lineNumber":10,"sourceCode":"import { DEBUG } from '@glimmer/env';\nimport type { CapturedArguments } from '@glimmer/interfaces';\nimport { toBool } from '@glimmer/global-context';\nimport { createComputeRef, valueForRef } from '@glimmer/reference/lib/reference';\n\nimport { internalHelper } from './internal-helper';\n\nexport const and = internalHelper(({ positional }: CapturedArguments) => {\n  if (DEBUG && positional.length < 2) {\n    throw new Error(`\\`and\\` expects at least two arguments, but received ${positional.length}.`);\n  }\n\n  return createComputeRef(\n    () => {\n      let last: unknown;\n      for (let i = 0; i < positional.length; i++) {\n        let arg = positional[i];\n        last = arg ? valueForRef(arg) : arg;\n        if (!toBool(last)) return last;\n      }\n      return last;\n    },\n    null,\n    'and'\n  );\n});\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@glimmer/runtime/lib/helpers/and.ts#L1-L27","documentation":"The {{and}} helper computes the logical AND of its positional arguments and requires at least two arguments to be meaningful. In DEBUG builds, invoking it with 0 or 1 positional args throws this error at computation time. Production builds skip the throw and just return the single/absent value.","triggerScenarios":"Calling the and helper with fewer than two positional arguments, e.g. {{and this.flag}}, {{and}}, or programmatic invocation of the helper with a positional array of length < 2 (DEBUG only).","commonSituations":"Template refactor that removed one of the arguments; dynamic argument lists (e.g. {{and ...conditions}}) that end up empty or single-element; misunderstanding that and accepts a single truthiness check like JavaScript's &&.","solutions":["Add the missing second (and further) arguments to the and helper call","Replace a single-argument and with the value itself or an inline expression (e.g. {{if this.flag this.flag}})","Guard dynamic argument spreads so at least two values are always passed","Use && inside a helper/computed property instead of and for single-value truthiness"],"exampleFix":"// before\n{{and this.isAdmin}}\n// after\n{{and this.isAdmin this.isActive}}","handlingStrategy":"validation","validationCode":"function safeAnd(...values: unknown[]): unknown {\n  if (values.length < 2) throw new Error('`and` requires at least two arguments');\n  return values.every(Boolean);\n}","typeGuard":"function hasMinArithmeticArgs(args: { positional: unknown[] }): args is { positional: [unknown, unknown, ...unknown[]] } {\n  return args.positional.length >= 2;\n}","tryCatchPattern":"try {\n  result = invokeHelper('and', positional);\n} catch (e) {\n  if (String(e?.message).startsWith('`and` expects at least two arguments')) {\n    result = Boolean(positional[0]); // degenerate fallback for single-arg case\n  } else { throw e; }\n}","preventionTips":["Pass at least two arguments to and/{{and}} every time","Replace single-argument and with the value directly or {{if}}","Guard dynamic spreads ({{and ...list}}) to ensure minimum length","Add template lint rules or unit tests covering helper call arity"],"tags":["glimmer","template","helper","arity"],"backgroundTag":"helper-arity-mismatch","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}