actualbudget/actual · error · Error

Invalid order field in "${trimmed}". Field name cannot be em

Error message

Invalid order field in "${trimmed}". Field name cannot be empty.

What it means

When an `--order-by` segment contains a colon, the part before the colon is the field name. If the segment starts with a colon (e.g. `:desc`) the field name is empty, which cannot produce a valid sort expression, so `parseOrderBy` throws this error.

Source

Thrown at packages/cli/src/commands/query.ts:27

/**
 * Parse order-by strings like "date:desc,amount:asc,id" into
 * AQL orderBy format: [{ date: 'desc' }, { amount: 'asc' }, 'id']
 */
export function parseOrderBy(
  input: string,
): Array<string | Record<string, string>> {
  return input.split(',').map(part => {
    const trimmed = part.trim();
    if (!trimmed) {
      throw new Error('--order-by contains an empty field');
    }
    const colonIndex = trimmed.indexOf(':');
    if (colonIndex === -1) {
      return trimmed;
    }
    const field = trimmed.slice(0, colonIndex).trim();
    if (!field) {
      throw new Error(
        `Invalid order field in "${trimmed}". Field name cannot be empty.`,
      );
    }
    const direction = trimmed.slice(colonIndex + 1);
    if (direction !== 'asc' && direction !== 'desc') {
      throw new Error(
        `Invalid order direction "${direction}" for field "${field}". Expected "asc" or "desc".`,
      );
    }
    return { [field]: direction };
  });
}

// TODO: Import schema from API once it exposes table/field metadata
const TABLE_SCHEMA: Record<
  string,
  Record<string, { type: string; ref?: string }>
> = {

View on GitHub (pinned to d4334cb6e6)

Solutions

  1. Put the field name before the colon: `--order-by date:desc`.
  2. If you only want ascending order, omit the colon entirely: `--order-by date`.
  3. Check that shell variables supplying the field name are set and non-empty.

Example fix

// before
actual pay --order-by ":desc"
// after
actual pay --order-by "date:desc"
Defensive patterns

Strategy: validation

Validate before calling

for (const part of orderByStr.split(',')) {
  const seg = part.trim();
  if (seg.includes(':') && !seg.split(':')[0].trim()) {
    throw new Error(`order segment "${seg}" is missing a field name`);
  }
}

Try / catch

try {
  await cli(['query', '--table', t, '--order-by', orderByStr]);
} catch (e) {
  if (e.message.includes('Field name cannot be empty')) {
    console.error('Put the field name before the colon, e.g. date:desc');
  }
}

Prevention

When it happens

Trigger: Passing `--order-by ":desc"` or `--order-by "date:desc,:asc"` — a colon-delimited segment whose pre-colon portion is empty after trimming.

Common situations: Typos when writing sort specs; template variables that expand to an empty field name (`--order-by "$FIELD:desc"` with FIELD unset).

Related errors


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