actualbudget/actual · error · CompileError

Unknown function: ${name}

Error message

Unknown function: ${name}

What it means

The AQL function compiler dispatches on the function name after the `$` prefix; the `default` branch throws this CompileError when the name does not match any known function (`$literal`, `$month`, `$collate`, etc.). It means a `$`-prefixed key was found that is not a registered function.

Source

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

    case '$condition':
      validateArgLength(args, 1);
      const conds = compileConditions(state, args[0]);
      return typed(conds.join(' AND '), 'boolean');

    case '$nocase':
      validateArgLength(args, 1);
      const [arg1] = valArray(state, args, ['string']);
      return typed(`${arg1} COLLATE NOCASE`, args[0].type);

    case '$literal': {
      validateArgLength(args, 1);
      if (!args[0].literal) {
        throw new CompileError('Literal not passed to $literal');
      }
      return args[0];
    }
    default:
      throw new CompileError(`Unknown function: ${name}`);
  }
});

const compileOp = saveStack('op', (state, fieldRef, opData) => {
  const { $transform, ...opExpr } = opData;
  const [op] = Object.keys(opExpr);

  const rhs = compileExpr(state, opData[op]);

  let lhs;
  if ($transform) {
    lhs = compileFunction(
      { ...state, implicitField: fieldRef },
      typeof $transform === 'string' ? { [$transform]: '$' } : $transform,
    );
  } else {
    lhs = compileExpr(state, '$' + fieldRef);
  }

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Verify the function name against the supported AQL function list in compiler.ts and fix the typo.
  2. Replace unsupported SQL aggregates with AQL equivalents (e.g. use calculated expressions or the summarize API).
  3. If the function should exist, confirm your loot-core version supports it; upgrade if it was added later.

Example fix

// before
{$months: '$date'}
// after
{$month: '$date'}
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN_FUNCS = new Set(['$literal', '$month', '$year', '$day', '$collate', /* ...from compiler.ts */]);
function assertKnownFunc(name) {
  if (!KNOWN_FUNCS.has(name)) throw new Error(`Unknown AQL function: ${name}`);
}

Type guard

const isKnownFunc = (name) => typeof name === 'string' && KNOWN_FUNCS.has(name);

Prevention

When it happens

Trigger: Calling `compileQuery`/`q()` with an expression like `{$sum: '$amount'}` where `$sum` (or any typo'd/unsupported name) is not in the compiler's function switch.

Common situations: Typos in function names, assuming SQL function names (SUM, COUNT) work directly in AQL, or using functions removed/renamed in a newer version of loot-core.

Related errors


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