{"record":{"id":"60657a98e6389ac0","repo":"affaan-m/ECC","slug":"flagname-requires-a-value","errorCode":null,"errorMessage":"${flagName} requires a value","messagePattern":"(.+?) requires a value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/discussion-audit.js","lineNumber":44,"sourceCode":"    '',\n    'Options:',\n    '  --format <text|json|markdown>',\n    '                             Output format (default: text)',\n    '  --json                     Alias for --format json',\n    '  --markdown                 Alias for --format markdown',\n    '  --write <path>             Write json or markdown output to a file',\n    '  --repo <owner/repo>        GitHub repo to inspect; repeatable',\n    '  --first <n>                Discussions to sample per repo (default: 100)',\n    '  --use-env-github-token     Keep GITHUB_TOKEN when invoking gh',\n    '  --exit-code                Return 2 when the audit is not ready',\n    '  --help, -h                 Show this help',\n  ].join('\\n'));\n}\n\nfunction readValue(args, index, flagName) {\n  const value = args[index + 1];\n  if (!value || value.startsWith('--')) {\n    throw new Error(`${flagName} requires a value`);\n  }\n  return value;\n}\n\nfunction parseIntegerFlag(value, flagName) {\n  const parsed = Number.parseInt(value, 10);\n  if (!Number.isFinite(parsed) || parsed <= 0) {\n    throw new Error(`Invalid ${flagName}: ${value}`);\n  }\n  return parsed;\n}\n\nfunction parseArgs(argv) {\n  const args = argv.slice(2);\n  const parsed = {\n    exitCode: false,\n    first: DEFAULT_DISCUSSION_FIRST,\n    format: 'text',","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/discussion-audit.js#L26-L62","documentation":"The readValue() helper in discussion-audit.js is used by --format, --write, --repo, and --first flags. It checks that argv[index + 1] is truthy and does not start with '--'. If the next token is undefined (flag is last) or looks like another flag (starts with '--'), it throws with the flag name. This prevents silently consuming one flag's name as another flag's value.","triggerScenarios":"Passing --write as the last argument; passing --format immediately followed by --json; passing --repo followed by --first; or any flag-value pair where the value is missing or is another flag.","commonSituations":"CI workflows that conditionally append flags but skip values when variables are empty; copy-paste errors; dynamic argument building that drops values.","solutions":["Provide a concrete value immediately after each flag, e.g. --format json --write report.md","If building commands dynamically, check that the value variable is truthy and does not start with '--' before appending the flag","Use the --flag=value syntax (e.g. --format=json) which avoids the two-token ambiguity entirely"],"exampleFix":"// before\nnode scripts/discussion-audit.js --write --format json\n// after\nnode scripts/discussion-audit.js --write report.json --format json\n// or\nnode scripts/discussion-audit.js --write=report.json --format=json","handlingStrategy":"validation","validationCode":"// Verify all value-expecting flags have companion values\nconst VALUE_FLAGS = new Set(['--format', '--write', '--repo', '--first']);\nconst argv = process.argv.slice(2);\nfor (let i = 0; i < argv.length; i++) {\n  if (VALUE_FLAGS.has(argv[i])) {\n    if (!argv[i + 1] || argv[i + 1].startsWith('--')) {\n      console.error(`${argv[i]} requires a value`);\n      process.exit(1);\n    }\n  }\n}\n// Alternatively, use --flag=value syntax to avoid the issue entirely","typeGuard":null,"tryCatchPattern":"try {\n  const options = parseArgs(process.argv);\n} catch (error) {\n  if (error.message.includes('requires a value')) {\n    console.error(error.message);\n    console.error('Tip: use --flag=value syntax to avoid ambiguity, e.g. --format=json');\n    usage();\n    process.exit(2);\n  }\n  throw error;\n}","preventionTips":["Use the --flag=value syntax (e.g. --write=report.json) to eliminate two-token ambiguity","Place each flag-value pair adjacent on the command line","When building commands dynamically, verify each value is truthy and does not start with '--'"],"tags":["cli","argument-parsing","discussion-audit"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}