{"record":{"id":"27051ae525f9c10f","repo":"ruvnet/ruflo","slug":"label-requires-a-json-argument","errorCode":null,"errorMessage":"${label} requires a JSON argument","messagePattern":"(.+?) requires a JSON argument","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/commands/policy.ts","lineNumber":21,"sourceCode":"  PolicyRequest,\n  PolicyRule,\n  PolicyState,\n} from '@claude-flow/security';\nimport type { Command, CommandContext, CommandResult } from '../types.js';\nimport { output } from '../output.js';\nimport {\n  autoMigratePolicyStateIfNeeded,\n  evaluatePolicyRequest,\n  loadPolicyState,\n  revokePolicyApproval,\n  setPolicyBudget,\n  setPolicyMode,\n  upsertPolicyRule,\n  verifyPolicyLedger,\n} from '../services/policy-runtime.js';\n\nfunction argJson<T>(value: string | undefined, label: string): T {\n  if (!value) throw new Error(`${label} requires a JSON argument`);\n  try { return JSON.parse(value) as T; }\n  catch { throw new Error(`${label} must be valid JSON`); }\n}\n\nfunction print(data: unknown): CommandResult {\n  output.writeln(JSON.stringify(data, null, 2));\n  return { success: true, exitCode: 0, data };\n}\n\nfunction requireInteractiveAdministrator(): void {\n  if (!process.stdin.isTTY || !process.stdout.isTTY) {\n    throw new Error('policy administration requires an interactive local terminal');\n  }\n}\n\nexport const policyCommand: Command = {\n  name: 'policy',\n  description: 'Agentic policy engine — evaluate actions, manage rules/approvals, and verify the decision ledger (ADR-324)',","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/cli/src/commands/policy.ts#L3-L39","documentation":"policy.ts's argJson() helper throws when a policy subcommand that takes a JSON payload (rule add, budget set, evaluate) is invoked without its JSON positional argument. It is the CLI's missing-argument guard that runs before JSON.parse is ever attempted.","triggerScenarios":"Running `ruflo policy rule add` with no third positional, `ruflo policy budget set` with no JSON, or `ruflo policy evaluate` with no request JSON — args[2] is undefined so the falsy check fires.","commonSituations":"Forgetting the JSON positional because most other subcommands pass data via flags; shell quoting that swallows the argument entirely (e.g. an empty '' which is also falsy).","solutions":["Append the JSON payload as a positional argument: ruflo policy rule add '{\"id\":\"r1\",\"effect\":\"deny\"}'","Copy the exact JSON shape from `ruflo policy --help` examples (budget set and evaluate examples are listed there)","Single-quote the JSON on POSIX shells so it arrives as one argv entry"],"exampleFix":"# before\nruflo policy budget set\n\n# after\nruflo policy budget set '{\"id\":\"daily-model\",\"action\":\"model.call\",\"maxCostUsd\":10,\"periodMs\":86400000}'","handlingStrategy":"validation","validationCode":"const opsNeedingJson = ['rule add', 'budget set', 'evaluate'];\nif (opsNeedingJson.includes(op) && !jsonPayload) {\n  throw new Error(`op '${op}' needs a JSON positional argument`);\n}\nawait runPolicyCli([...args, jsonPayload]);","typeGuard":"function hasJsonArg(v: string | undefined): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Keep the JSON payload in a variable and assert it is non-empty before composing the command","Note that an empty string is treated as missing — trim user input first","Script the exact examples from `policy --help` rather than composing from memory"],"tags":["cli","policy","arguments","json"],"backgroundTag":"missing-required-argument","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}