{"record":{"id":"5689b6a56426c296","repo":"actualbudget/actual","slug":"invalid-order-direction-direction-for-field","errorCode":null,"errorMessage":"Invalid order direction \"${direction}\" for field \"${field}\". Expected \"asc\" or \"desc\".","messagePattern":"Invalid order direction \"(.+?)\" for field \"(.+?)\"\\. Expected \"asc\" or \"desc\"\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/query.ts","lineNumber":33,"sourceCode":"): Array<string | Record<string, string>> {\n  return input.split(',').map(part => {\n    const trimmed = part.trim();\n    if (!trimmed) {\n      throw new Error('--order-by contains an empty field');\n    }\n    const colonIndex = trimmed.indexOf(':');\n    if (colonIndex === -1) {\n      return trimmed;\n    }\n    const field = trimmed.slice(0, colonIndex).trim();\n    if (!field) {\n      throw new Error(\n        `Invalid order field in \"${trimmed}\". Field name cannot be empty.`,\n      );\n    }\n    const direction = trimmed.slice(colonIndex + 1);\n    if (direction !== 'asc' && direction !== 'desc') {\n      throw new Error(\n        `Invalid order direction \"${direction}\" for field \"${field}\". Expected \"asc\" or \"desc\".`,\n      );\n    }\n    return { [field]: direction };\n  });\n}\n\n// TODO: Import schema from API once it exposes table/field metadata\nconst TABLE_SCHEMA: Record<\n  string,\n  Record<string, { type: string; ref?: string }>\n> = {\n  transactions: {\n    id: { type: 'id' },\n    account: { type: 'id', ref: 'accounts' },\n    date: { type: 'date' },\n    amount: { type: 'integer' },\n    payee: { type: 'id', ref: 'payees' },","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/cli/src/commands/query.ts#L15-L51","documentation":"When an `--order-by` segment uses the `field:direction` form, the direction after the colon must be exactly `asc` or `desc`. Anything else (including mixed case, misspellings, or a missing direction like `date:`) is rejected with this error.","triggerScenarios":"Passing `--order-by \"date:ascending\"`, `--order-by \"date:DESC\"`, or `--order-by \"date:\"` — any post-colon value other than the literal lowercase `asc` or `desc`.","commonSituations":"Muscle-memory from SQL (`ORDER BY date ASC` spelled out as `ascending`); uppercase direction from environment variables; forgotten direction after the colon.","solutions":["Use lowercase `asc` or `desc`: `--order-by date:desc`.","Drop the colon and direction entirely for default ascending order: `--order-by date`.","Normalize/uppercase-to-lowercase any direction sourced from variables before passing it."],"exampleFix":"// before\nactual pay --order-by \"date:DESC\"\n// after\nactual pay --order-by \"date:desc\"","handlingStrategy":"validation","validationCode":"if (direction !== undefined && direction !== 'asc' && direction !== 'desc') {\n  throw new Error(`direction must be \"asc\" or \"desc\", got \"${direction}\"`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli(['query', '--table', t, '--order-by', `${field}:${direction}`]);\n} catch (e) {\n  if (e.message.includes('Invalid order direction')) {\n    console.error('Use lowercase asc or desc');\n  }\n}","preventionTips":["Only use the exact lowercase strings asc and desc.","Normalize (toLowerCase) any direction coming from config/env, and reject non-enum values there.","Omit the direction entirely when ascending order is fine."],"tags":["cli","validation","query"],"backgroundTag":"invalid-enum-value","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}