{"record":{"id":"23f24c791b4d4656","repo":"affaan-m/ECC","slug":"write-requires-json-or-markdown","errorCode":null,"errorMessage":"--write requires --json or --markdown","messagePattern":"--write requires --json or --markdown","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/status.js","lineNumber":528,"sourceCode":"      installStateProjection,\n    };\n    payload.githubCoordination = summarizeGithubCoordination(payload.workItems);\n\n    if (options.json) {\n      const output = `${JSON.stringify(payload, null, 2)}\\n`;\n      if (options.writePath) {\n        writeOutput(options.writePath, output);\n      }\n      process.stdout.write(output);\n    } else if (options.markdown) {\n      const output = renderMarkdown(payload);\n      if (options.writePath) {\n        writeOutput(options.writePath, output);\n      }\n      process.stdout.write(output);\n    } else {\n      if (options.writePath) {\n        throw new Error('--write requires --json or --markdown');\n      }\n      printHuman(payload);\n    }\n\n    if (options.exitCode && payload.readiness.status !== 'ok') {\n      process.exitCode = 2;\n    }\n  } catch (error) {\n    console.error(`Error: ${error.message}`);\n    process.exit(1);\n  } finally {\n    if (store) {\n      store.close();\n    }\n  }\n}\n\nif (require.main === module) {","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/status.js#L510-L546","documentation":"In scripts/status.js main(), the --write option only works when a machine-readable format (--json or --markdown) was selected, because only those code paths produce a serializable `output` string to save. When a writePath is set but the human (printHuman) path is taken, the script throws \"--write requires --json or --markdown\" instead of silently ignoring --write.","triggerScenarios":"Running `node scripts/status.js --write out.txt` without --json or --markdown; main() reaches the else branch (human output) and, seeing options.writePath set, throws.","commonSituations":"Assuming --write works for the default human-readable output; stripping the format flag from a command line while keeping --write; wrapper scripts that add --write unconditionally.","solutions":["Add --json or --markdown alongside --write.","Remove --write if you only want the human-readable console output.","In wrappers, only pass --write when a format flag is also present."],"exampleFix":"// before\nnode scripts/status.js --write out.txt\n// after\nnode scripts/status.js --json --write out.json","handlingStrategy":"validation","validationCode":"const wantsWrite = process.argv.includes('--write');\nconst hasFormat = process.argv.includes('--json') || process.argv.includes('--markdown');\nif (wantsWrite && !hasFormat) throw new Error('--write requires --json or --markdown');","typeGuard":null,"tryCatchPattern":"try {\n  runStatus(argv);\n} catch (e) {\n  if (e.message.includes('--write requires')) {\n    console.error('Add --json or --markdown when using --write.');\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Pair --write with --json or --markdown in every wrapper/alias.","Remember --write only persists machine-readable output, not the human view.","Add a pre-flight check in scripts that build status.js command lines."],"tags":["cli","flag-combination","output-format"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}