actualbudget/actual · error · CompileError

Too few arguments

Error message

Too few arguments

What it means

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.

Source

Thrown at packages/loot-core/src/server/aql/compiler.ts:374

      const value = castedExpr.value.replace(/'/g, "''");
      return `'${value}'`;
    }
  }

  return castedExpr.value;
}

function valArray(state, arr: unknown[], types?: string[]) {
  return arr.map((value, idx) => val(state, value, types ? types[idx] : null));
}

function validateArgLength(arr: unknown[], min: number, max?: number) {
  if (max == null) {
    max = min;
  }

  if (min != null && arr.length < min) {
    throw new CompileError('Too few arguments');
  }
  if (max != null && arr.length > max) {
    throw new CompileError('Too many arguments');
  }
}

//// Nice errors

function saveStack(type, func) {
  return (state, ...args) => {
    if (state == null || state.compileStack == null) {
      throw new CompileError(
        'This function cannot track error data. ' +
          'It needs to accept the compiler state as the first argument.',
      );
    }

    state.compileStack.push({ type, args });

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Count the function's required arguments and supply all of them
  2. Check that optional arguments you intended to pass aren't being dropped as undefined/null before compiling
  3. Consult the function schema (in the compiler's function table) for exact arity
  4. If arg count is dynamic, validate length before building the query object

Example fix

// before
{ $cond: [amount > 0] }
// after
{ $cond: [amount > 0, 'credit', 'debit'] }
Defensive patterns

Strategy: validation

Validate before calling

if (args.filter(a => a !== undefined).length < required) {
  throw new Error(`${fnName} requires ${required} arguments, got ${args.length}`);
}

Try / catch

try {
  compileQuery(query);
} catch (e) {
  if (e.message === 'Too few arguments') {
    console.error('Missing required argument in query function call', { query });
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of actualbudget/actual@d4334cb6e6 (2026-08-29). Data as JSON: /api/errors/b2b4b561cef96f60. Report an issue: GitHub.