{"record":{"id":"8b49312972ab4cc8","repo":"actualbudget/actual","slug":"invalid-order-field-in-trimmed-field-name-ca","errorCode":null,"errorMessage":"Invalid order field in \"${trimmed}\". Field name cannot be empty.","messagePattern":"Invalid order field in \"(.+?)\"\\. Field name cannot be empty\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/query.ts","lineNumber":27,"sourceCode":"/**\n * Parse order-by strings like \"date:desc,amount:asc,id\" into\n * AQL orderBy format: [{ date: 'desc' }, { amount: 'asc' }, 'id']\n */\nexport function parseOrderBy(\n  input: string,\n): 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> = {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/cli/src/commands/query.ts#L9-L45","documentation":"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.","triggerScenarios":"Passing `--order-by \":desc\"` or `--order-by \"date:desc,:asc\"` — a colon-delimited segment whose pre-colon portion is empty after trimming.","commonSituations":"Typos when writing sort specs; template variables that expand to an empty field name (`--order-by \"$FIELD:desc\"` with FIELD unset).","solutions":["Put the field name before the colon: `--order-by date:desc`.","If you only want ascending order, omit the colon entirely: `--order-by date`.","Check that shell variables supplying the field name are set and non-empty."],"exampleFix":"// before\nactual pay --order-by \":desc\"\n// after\nactual pay --order-by \"date:desc\"","handlingStrategy":"validation","validationCode":"for (const part of orderByStr.split(',')) {\n  const seg = part.trim();\n  if (seg.includes(':') && !seg.split(':')[0].trim()) {\n    throw new Error(`order segment \"${seg}\" is missing a field name`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cli(['query', '--table', t, '--order-by', orderByStr]);\n} catch (e) {\n  if (e.message.includes('Field name cannot be empty')) {\n    console.error('Put the field name before the colon, e.g. date:desc');\n  }\n}","preventionTips":["Always write segments as field or field:dir — never start with a colon.","Verify shell variables supplying field names are set and non-empty.","Validate each comma-separated segment in wrapper scripts before invoking."],"tags":["cli","validation","query"],"backgroundTag":"invalid-flag-value","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}