{"record":{"id":"787c82033041e2a5","repo":"JuliusBrussee/caveman","slug":"json-cannot-open-a-browser","errorCode":null,"errorMessage":"--json cannot open a browser","messagePattern":"--json cannot open a browser","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/stats-cli.ts","lineNumber":56,"sourceCode":"    if (seen.has(arg)) throw new Error(`duplicate ${arg}`);\n    seen.add(arg);\n    if (valueFlags.has(arg)) {\n      const value = argv[++i];\n      if (!value || value.startsWith(\"--\") || /[\\u0000-\\u001f\\u007f]/u.test(value)) throw new Error(`${arg} requires a value`);\n      if (arg === \"--days\" && (!/^\\d+$/u.test(value) || Number(value) < 1 || Number(value) > 3660)) {\n        throw new Error(\"--days must be an integer from 1 to 3660\");\n      }\n      if (arg === \"--out\") result.out = value;\n      else result.filters.push(arg, value);\n    } else if (arg === \"--json\") result.json = true;\n    else if (arg === \"--plain\" || arg === \"--no-open\") result.plain = true;\n    else if (arg === \"--open\") result.open = true;\n    else if (arg === \"--all-time\") result.filters.push(\"--days\", \"0\");\n    else throw new Error(`unknown option ${arg}`);\n  }\n  if (seen.has(\"--days\") && seen.has(\"--all-time\")) throw new Error(\"choose --days or --all-time\");\n  if (result.plain && result.open) throw new Error(\"choose --plain or --open\");\n  if (result.json && result.open) throw new Error(\"--json cannot open a browser\");\n  return result;\n}\n\ntype StatsMetrics = {\n  requests: number;\n  successful_requests: number;\n  failed_requests: number;\n  input_tokens: number;\n  output_tokens: number;\n  cache_read_tokens: number;\n  cache_write_tokens: number;\n  complete_usage_requests: number;\n  partial_usage_requests: number;\n  measured_requests: number;\n  unmeasured_requests: number;\n  before_tokens: number;\n  after_tokens: number;\n  saved_tokens: number;","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/stats-cli.ts#L38-L74","documentation":"Option conflict in parseStatsOptions: --json and --open are incompatible because JSON output goes to stdout while --open requires rendering an HTML report in a browser; the parser refuses to pretend both can happen.","triggerScenarios":"`stats --json --open`; CI scripts that grew a --open flag added by hand; docs/examples mixing the two flags.","commonSituations":"Automation adding --json for parsing while a developer appends --open to eyeball results; aliasing stats with --open permanently then adding --json in a script.","solutions":["Keep only --json when output is consumed programmatically (pipe to jq, write to file)","Keep only --open when a human wants the rendered view (optionally with --plain for terminal)","Split into two invocations if both JSON and a browsable view are needed"],"exampleFix":"// before\nmyapp stats --json --open\n// after\nmyapp stats --json > stats.json","handlingStrategy":"validation","validationCode":"if (argv.includes(\"--json\") && argv.includes(\"--open\")) {\n  throw new Error(\"--json and --open are mutually exclusive\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  const opts = parseStatsOptions(argv);\n} catch (e) {\n  if (e.message === \"--json cannot open a browser\") {\n    console.error(e.message); process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Reserve --json for automation and --open for humans; never mix in one invocation","In CI, forbid --open via lint/wrapper checks","Split needs into two invocations: one writing JSON, one opening the view"],"tags":["cli","conflicting-options"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}