{"record":{"id":"dcc9d1718b2dd07c","repo":"affaan-m/ECC","slug":"write-requires-json-markdown-or-format-j","errorCode":null,"errorMessage":"--write requires --json, --markdown, or --format json|markdown","messagePattern":"--write requires --json, --markdown, or --format json\\|markdown","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/discussion-audit.js","lineNumber":149,"sourceCode":"    if (arg === '--use-env-github-token') {\n      parsed.useEnvGithubToken = true;\n      continue;\n    }\n\n    if (arg === '--exit-code') {\n      parsed.exitCode = true;\n      continue;\n    }\n\n    throw new Error(`Unknown argument: ${arg}`);\n  }\n\n  if (!['text', 'json', 'markdown'].includes(parsed.format)) {\n    throw new Error(`Invalid format: ${parsed.format}. Use text, json, or markdown.`);\n  }\n\n  if (parsed.writePath && parsed.format === 'text') {\n    throw new Error('--write requires --json, --markdown, or --format json|markdown');\n  }\n\n  return parsed;\n}\n\nfunction buildReport(options) {\n  const repos = options.repos.length > 0 ? options.repos : DEFAULT_REPOS;\n  const repoReports = repos.map(repo => {\n    try {\n      return {\n        repo,\n        discussions: fetchDiscussionSummary(repo, options),\n      };\n    } catch (error) {\n      return {\n        repo,\n        error: error.message,\n        discussions: emptyDiscussionSummary(),","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/discussion-audit.js#L131-L167","documentation":"discussion-audit.js supports writing output to a file via --write, but only for structured formats (json or markdown). The default format is 'text', which is designed for terminal display. If --write is provided without explicitly selecting json or markdown format, the post-parse validation at line 148 detects that parsed.writePath is set while parsed.format is still 'text' and throws. This prevents writing unstructured human-readable text to a file.","triggerScenarios":"Passing --write report.json without also passing --json, --markdown, or --format json|markdown. Even though the filename has a .json extension, the script defaults to text format unless told otherwise.","commonSituations":"Users assuming the file extension determines the format; CI workflows that add --write but forget the format flag; copy-paste from examples that omit the format flag.","solutions":["Add --json or --markdown alongside --write, e.g. --write report.json --json","Use --format json or --format markdown explicitly","If you want text output, redirect stdout to a file instead: node scripts/discussion-audit.js > report.txt"],"exampleFix":"// before\nnode scripts/discussion-audit.js --write report.json\n// after\nnode scripts/discussion-audit.js --write report.json --json\n// or\nnode scripts/discussion-audit.js --write report.json --format json","handlingStrategy":"validation","validationCode":"// Ensure --write is always accompanied by a structured format\nconst argv = process.argv.slice(2);\nconst hasWrite = argv.includes('--write') || argv.some(a => a.startsWith('--write='));\nconst hasStructuredFormat = argv.includes('--json') || argv.includes('--markdown')\n  || argv.some(a => a.startsWith('--format=json') || a.startsWith('--format=markdown'))\n  || (argv.includes('--format') && ['json', 'markdown'].includes((argv[argv.indexOf('--format') + 1] || '').toLowerCase()));\nif (hasWrite && !hasStructuredFormat) {\n  console.error('--write requires --json, --markdown, or --format json|markdown');\n  console.error('Add --json or --markdown to your command.');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const options = parseArgs(process.argv);\n} catch (error) {\n  if (error.message.includes('--write requires')) {\n    console.error(error.message);\n    console.error('Add --json or --markdown to the command when using --write.');\n    console.error('For text output to a file, redirect stdout: node scripts/discussion-audit.js > report.txt');\n    process.exit(2);\n  }\n  throw error;\n}","preventionTips":["Always pair --write with --json or --markdown — the file extension does not determine the format","For text output, redirect stdout to a file instead of using --write","In CI, use --json --write report.json for machine-readable output"],"tags":["cli","argument-parsing","validation","discussion-audit"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}