{"record":{"id":"b2b4b561cef96f60","repo":"actualbudget/actual","slug":"too-few-arguments","errorCode":null,"errorMessage":"Too few arguments","messagePattern":"Too few arguments","errorType":"exception","errorClass":"CompileError","httpStatus":null,"severity":"error","filePath":"packages/loot-core/src/server/aql/compiler.ts","lineNumber":374,"sourceCode":"      const value = castedExpr.value.replace(/'/g, \"''\");\n      return `'${value}'`;\n    }\n  }\n\n  return castedExpr.value;\n}\n\nfunction valArray(state, arr: unknown[], types?: string[]) {\n  return arr.map((value, idx) => val(state, value, types ? types[idx] : null));\n}\n\nfunction validateArgLength(arr: unknown[], min: number, max?: number) {\n  if (max == null) {\n    max = min;\n  }\n\n  if (min != null && arr.length < min) {\n    throw new CompileError('Too few arguments');\n  }\n  if (max != null && arr.length > max) {\n    throw new CompileError('Too many arguments');\n  }\n}\n\n//// Nice errors\n\nfunction saveStack(type, func) {\n  return (state, ...args) => {\n    if (state == null || state.compileStack == null) {\n      throw new CompileError(\n        'This function cannot track error data. ' +\n          'It needs to accept the compiler state as the first argument.',\n      );\n    }\n\n    state.compileStack.push({ type, args });","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/loot-core/src/server/aql/compiler.ts#L356-L392","documentation":"validateArgLength checks the compiled argument array of a query function against its declared min/max arity. If fewer arguments than the minimum are supplied, CompileError 'Too few arguments' is thrown during compileFunction.","triggerScenarios":"Calling an AQL function like $cond, $substr, or date constructors with fewer positional/named arguments than required, e.g. $cond with 2 args instead of 3, or an empty argument list for a 1-arg function.","commonSituations":"Hand-written query expressions missing an argument; a query builder that drops null/undefined args so a required slot disappears; copy-pasted expressions with an argument accidentally deleted.","solutions":["Count the function's required arguments and supply all of them","Check that optional arguments you intended to pass aren't being dropped as undefined/null before compiling","Consult the function schema (in the compiler's function table) for exact arity","If arg count is dynamic, validate length before building the query object"],"exampleFix":"// before\n{ $cond: [amount > 0] }\n// after\n{ $cond: [amount > 0, 'credit', 'debit'] }","handlingStrategy":"validation","validationCode":"if (args.filter(a => a !== undefined).length < required) {\n  throw new Error(`${fnName} requires ${required} arguments, got ${args.length}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  compileQuery(query);\n} catch (e) {\n  if (e.message === 'Too few arguments') {\n    console.error('Missing required argument in query function call', { query });\n  }\n  throw e;\n}","preventionTips":["Check the function schema for required arity before building the call","Avoid conditionally dropping required args (null/undefined forwarding)","Unit-test query builders against known arities"],"tags":["aql","query-compiler","argument-validation"],"backgroundTag":"wrong-argument-count","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}