{"record":{"id":"a51bb0410ce571cb","repo":"santifer/career-ops","slug":"missing-value-for-arg","errorCode":null,"errorMessage":"Missing value for ${arg}","messagePattern":"Missing value for (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"application-answers.mjs","lineNumber":407,"sourceCode":"  const end = nextHeading ? afterHeading + nextHeading.index : report.length;\n  const before = report.slice(0, start).trimEnd();\n  const after = report.slice(end).trimStart();\n\n  return [before, section, after].filter(Boolean).join('\\n\\n') + '\\n';\n}\n\nfunction parseArgs(argv) {\n  const args = {};\n  for (let i = 0; i < argv.length; i += 1) {\n    const arg = argv[i];\n    if (arg === '--help' || arg === '-h') args.help = true;\n    else if (arg === '--read') args.read = true;\n    else if (arg === '--read-draft') args.readDraft = true;\n    else if (arg === '--strict') args.strict = true;\n    else if (arg.startsWith('--')) {\n      const value = argv[i + 1];\n      if (!value || value.startsWith('--')) {\n        throw new Error(`Missing value for ${arg}`);\n      }\n      args[arg.slice(2)] = value;\n      i += 1;\n    }\n  }\n  return args;\n}\n\nfunction usage() {\n  return [\n    'Usage: node application-answers.mjs --report <report.md> --input <answers.json> [--state filled|submitted] [--date YYYY-MM-DD]',\n    '       node application-answers.mjs --report <report.md> --read [--strict]',\n    '       node application-answers.mjs --report <report.md> --read-draft',\n    '',\n    'The input JSON may contain: freeText, selections, fieldValues, files, date, state.',\n    '--read prints the parsed ## Application Answers snapshot as JSON (null when the section is absent).',\n    '--strict makes --read refuse a partially unreadable section, naming every line it could not parse,',\n    'instead of skipping it. Recovery callers (modes/apply.md) want the refusal; the default stays total.',","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/application-answers.mjs#L389-L425","documentation":"parseArgs in application-answers.mjs treats any unrecognized --flag as a flag-with-value pair, consuming the next argv element as its value. If the next element is missing or itself starts with '--' (i.e. it is another flag), there is no value to consume, so it throws \"Missing value for <flag>\". This also fires for genuine typos of known value-taking flags.","triggerScenarios":"Running the CLI with a value-taking flag at the end of the command line with nothing after it (e.g. `--state`), or with the next token being another flag (e.g. `--state --strict`), or passing a misspelled flag like `--stat filled` that the parser then treats as an unknown value-taking option.","commonSituations":"Shell scripts where a variable holding the value is empty (`--state \"$STATE\"` with STATE unset); copying an example and dropping the value; typos in flag names so the parser doesn't recognize them as boolean flags.","solutions":["Supply the value immediately after the flag: `node application-answers.mjs --state submitted`.","Check shell variables feeding the command are non-empty (quote and default them: \"${STATE:?STATE not set}\").","Fix flag-name typos — an unknown flag followed by another flag triggers this error even if you intended it as a boolean."],"exampleFix":"// before\nnode application-answers.mjs --write --state   # value missing\n// after\nSTATE=submitted node application-answers.mjs --write --state \"$STATE\"","handlingStrategy":"validation","validationCode":"const VALUE_FLAGS = new Set(['--state', '--date', '--company', '--question']);\nfor (const f of VALUE_FLAGS) {\n  const i = process.argv.indexOf(f);\n  if (i !== -1 && (!process.argv[i + 1] || process.argv[i + 1].startsWith('--'))) {\n    throw new Error(`${f} requires a value`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const args = parseArgs(process.argv.slice(2));\n} catch (err) {\n  if (err.message.startsWith('Missing value for')) {\n    console.error(`${err.message}. Usage: application-answers.mjs --<flag> <value>`);\n    process.exit(2);\n  }\n  throw err;\n}","preventionTips":["In shell scripts, require value variables with \"${STATE:?STATE is unset}\" before invoking the CLI.","Quote values that may start with '-' or look like flags (pass as --flag=\"value\" and verify).","Double-check flag spelling: unrecognized flags are silently treated as value-taking options."],"tags":["cli","arguments","parsing"],"backgroundTag":"missing-cli-argument","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}