actualbudget/actual · error · CompileError

Too many arguments

Error message

Too many arguments

What it means

The counterpart of 'Too few arguments': validateArgLength throws when a function call supplies more arguments than the declared maximum. CompileError 'Too many arguments' is raised from compileFunction.

Solutions

  1. Remove the extra arguments to match the function's declared arity
  2. Check the function schema for the accepted min/max argument count
  3. If you need optional behavior, use the documented function for it instead of extra args
  4. Verify no duplicated/accidental element exists in the arguments array

Example fix

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

Strategy: validation

Validate before calling

if (args.length > maxAllowed) {
  throw new Error(`${fnName} accepts at most ${maxAllowed} arguments, got ${args.length}`);
}

Try / catch

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

Prevention

When it happens

Trigger: Passing extra positional arguments to a fixed-arity AQL function, e.g. 4 args to $cond (max 3) or 2 args to a unary function like $neg.

Common situations: Migrating from another query language's syntax that allows optional extra params; typos leaving a stray argument in the array; a builder appending default arguments the schema doesn't accept.

Related errors


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

Appendix: source

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

  }

  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 });
    const ret = func(state, ...args);
    state.compileStack.pop();
    return ret;

View on GitHub (pinned to d4334cb6e6)