{"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/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/commands/policy.ts#L3-L39","documentation":"Thrown by the argJson() helper in the Ruflo policy CLI command when a JSON-valued argument is entirely absent (undefined or empty string). The helper refuses to coerce a missing argument to a default object because policy rules and budgets are security-sensitive — silently substituting {} could write a no-op rule. It is a usage error, not a runtime fault.","triggerScenarios":"Running `ruflo policy rule add`, `budget set`, or `evaluate` without the trailing JSON positional argument (e.g. `ruflo policy rule add` with no third token, or `policy budget set` with args[2] unset). argJson(value, label) is called with value === undefined.","commonSituations":"Forgetting the JSON blob in a script, quoting that swallows the argument, passing the JSON via a flag the command does not read, or copy-pasting an example that drops the trailing quoted object.","solutions":["Append a valid JSON object as the next positional argument: `ruflo policy budget set '{\"id\":\"daily\",\"action\":\"model.call\",\"maxCostUsd\":10,\"periodMs\":86400000}'`.","If building the call from a shell variable, ensure it is non-empty and properly single-quoted so the shell does not strip it.","Check the operation's argument order against the examples block at the bottom of policy.ts (rule add takes args[2], budget set takes args[2])."],"exampleFix":"// before\nruflo policy budget set\n// after\nruflo policy budget set '{\"id\":\"daily\",\"action\":\"model.call\",\"maxCostUsd\":10,\"periodMs\":86400000}'","handlingStrategy":"validation","validationCode":"function buildPolicyArgs(op: string, json?: string): string[] {\n  if ((op === 'rule' || op === 'budget') && !json) {\n    throw new Error(`operation '${op}' requires a non-empty JSON argument`);\n  }\n  return json === undefined ? [op] : [op, json];\n}\n// before invoking the policy command:\nbuildPolicyArgs('budget', process.env.POLICY_JSON); // throws early if missing","typeGuard":"const isNonEmptyString = (v: unknown): v is string =>\n  typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  await runPolicyCommand(argv);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e);\n  if (msg.endsWith('requires a JSON argument')) {\n    console.error('Usage: ruflo policy <rule|budget|evaluate> \\'<json>\\'');\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["Always pass the JSON as a single-quoted positional argument.","Validate non-emptiness before invoking the CLI rather than relying on its error.","Generate JSON programmatically (jq -c) instead of hand-typing."],"tags":["cli","validation","json","policy","ruflo"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}