{"record":{"id":"5ea5522b70d9a8b3","repo":"actualbudget/actual","slug":"either-data-or-file-is-required","errorCode":null,"errorMessage":"Either --data or --file is required","messagePattern":"Either --data or --file is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/input.ts","lineNumber":20,"sourceCode":"\nexport function readJsonInput(cmdOpts: {\n  data?: string;\n  file?: string;\n}): unknown {\n  if (cmdOpts.data && cmdOpts.file) {\n    throw new Error('Cannot use both --data and --file');\n  }\n  if (cmdOpts.data) {\n    return JSON.parse(cmdOpts.data);\n  }\n  if (cmdOpts.file) {\n    const content =\n      cmdOpts.file === '-'\n        ? readFileSync(0, 'utf-8')\n        : readFileSync(cmdOpts.file, 'utf-8');\n    return JSON.parse(content);\n  }\n  throw new Error('Either --data or --file is required');\n}\n","sourceCodeStart":2,"sourceCodeEnd":22,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/cli/src/input.ts#L2-L22","documentation":"readJsonInput requires a JSON source: if neither --data nor --file is provided it throws this error. The commands that consume JSON payloads (transactions import, rules, schedules, fields) cannot proceed without input, so this fails fast before any parsing or network work.","triggerScenarios":"Calling a command that needs a JSON body without --data or --file; intending to pipe stdin but forgetting that '-' must be given to --file; an empty variable expanding to nothing ($DATA unset with --data \"$DATA\").","commonSituations":"Script where the payload variable was never set; docs example where the user omitted the file argument; forgetting `--file -` when piping from another command.","solutions":["Add --file payload.json pointing at your JSON file.","Or pass the JSON inline with --data '{...}'.","When piping from stdin, use --file - explicitly (e.g. cat txns.json | cmd --file -).","Check in scripts that the variable holding the JSON is non-empty before invoking."],"exampleFix":"// before\nactual-cli transactions --sync-id $ID\n// after\nactual-cli transactions --sync-id $ID --file txns.json","handlingStrategy":"validation","validationCode":"if (!cmdOpts.data && !cmdOpts.file) {\n  throw new Error('No JSON input: provide --data, --file <path>, or --file - for stdin.');\n}\nif (cmdOpts.file === '-' && process.stdin.isTTY) {\n  throw new Error('--file - given but nothing is piped to stdin.');\n}","typeGuard":"function hasJsonInput(o: { data?: string; file?: string }): o is typeof o & ({ data: string } | { file: string }) {\n  return Boolean(o.data || o.file);\n}","tryCatchPattern":"try {\n  const json = readJsonInput({ data: opts.data, file: opts.file });\n} catch (err) {\n  if (err instanceof Error && err.message === 'Either --data or --file is required') {\n    console.error('Supply the JSON payload via --data or --file (use - for stdin).');\n    process.exit(2);\n  }\n  throw err;\n}","preventionTips":["Always pass an explicit payload flag in scripts; avoid --data \"$VAR\" with unset vars (use ${VAR:?}).","Use `cmd --file - < payload.json` for piped input rather than relying on implicit stdin.","Check file existence with [ -f \"$FILE\" ] before passing --file.","Default payload paths in config/wrappers so the flag is never omitted."],"tags":["cli","input","missing-option"],"backgroundTag":"missing-required-option","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}