{"record":{"id":"a51bb0410ce571cb","repo":"santifer/career-ops","slug":"missing-value-for-arg","errorCode":null,"errorMessage":"Missing value for ${arg}","messagePattern":"Missing value for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"application-answers.mjs","lineNumber":168,"sourceCode":"  const start = heading.index;\n  const afterHeading = start + heading[0].length;\n  const nextHeading = /^## .+$/m.exec(report.slice(afterHeading));\n  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.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    '',\n    'The input JSON may contain: freeText, selections, fieldValues, files, date, state.',\n  ].join('\\n');\n}\n\nasync function main() {\n  let args;","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/santifer/career-ops/blob/9b17a8ac97b398a496b38e423ae24e433b43254f/application-answers.mjs#L150-L186","documentation":"Thrown by `parseArgs` in application-answers.mjs when a `--flag` is the last token or is immediately followed by another `--flag`. Each option requires a value; CLI conventions treat a following `--` as a missing operand rather than a value, so the parser refuses to silently consume a flag name as data.","triggerScenarios":"Running `node application-answers.mjs --report --input a.json` (no value after `--report`); ending with `--input` as the last arg; `--state` followed by `--date`; any `--key` with no positional value.","commonSituations":"User forgets the value; shell quoting eats an empty string (`--report \"\"` is technically allowed but a missing following token is not); copy-paste from docs that truncated a line; argument reordering that left a flag dangling.","solutions":["Provide a value for every `--flag`: `--report <path> --input <path> [--state <s>] [--date <d>]`.","If you intended an empty value, pass an explicit empty string (`--report \"\"`) — though here that likely fails downstream; prefer omitting the flag.","Quote values containing spaces and check the shell didn't strip them.","Run with `--help` to see the documented argument order and required flags.","Validate argv length / shape in a wrapper before invoking if generating the command programmatically."],"exampleFix":"// before\nnode application-answers.mjs --report --input answers.json\n// after\nnode application-answers.mjs --report reports/042-acme.md --input answers.json","handlingStrategy":"validation","validationCode":"function ensureValues(argv) {\n  for (let i = 0; i < argv.length; i++) {\n    if (argv[i].startsWith('--')) {\n      const v = argv[i + 1];\n      if (!v || v.startsWith('--')) throw new Error(`Missing value for ${argv[i]}`);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try { runCli(argv); }\ncatch (e) {\n  if (/Missing value for/.test(e.message)) {\n    printUsage(); // show the documented arg order\n  } else throw e;\n}","preventionTips":["Quote each flag's value and verify none are accidentally the next flag.","Generate CLI commands from a typed arg builder that rejects missing values.","Always expose `--help` and reference it on error.","Avoid positional reordering that leaves a flag dangling."],"tags":["validation","cli","argv","application-answers"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}