{"record":{"id":"fd9bd6e0a1c18dba","repo":"itwanger/toBeBetterJavaer","slug":"missing-value-for-argv-index","errorCode":null,"errorMessage":"Missing value for ${argv[index]}","messagePattern":"Missing value for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/convert-mdnice-images-to-cdn.js","lineNumber":109,"sourceCode":"      options.limit = parsePositiveInt(arg.slice(\"--limit=\".length), \"--limit\");\n    } else if (arg.startsWith(\"-\")) {\n      throw new Error(`Unknown option: ${arg}`);\n    } else {\n      options.targets.push(path.resolve(ROOT_DIR, arg));\n    }\n  }\n\n  if (options.targets.length === 0) {\n    options.targets.push(DEFAULT_TARGET);\n  }\n\n  return options;\n}\n\nfunction requireValue(argv, index) {\n  const value = argv[index + 1];\n  if (!value || value.startsWith(\"-\")) {\n    throw new Error(`Missing value for ${argv[index]}`);\n  }\n  return value;\n}\n\nfunction parseList(value) {\n  return value\n    .split(\",\")\n    .map((item) => item.trim())\n    .filter(Boolean);\n}\n\nfunction parsePositiveInt(value, optionName) {\n  const parsed = Number.parseInt(value, 10);\n  if (!Number.isFinite(parsed) || parsed <= 0) {\n    throw new Error(`${optionName} must be a positive integer`);\n  }\n  return parsed;\n}","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/itwanger/toBeBetterJavaer/blob/6617f5fd0b0597735bdc028f2fcd036817877327/scripts/convert-mdnice-images-to-cdn.js#L91-L127","documentation":"Thrown by requireValue() in scripts/convert-mdnice-images-to-cdn.js when a value-taking option (--env, --domains, --prefix, --concurrency, --limit) is the last token or its next token starts with '-'. The parser refuses to consume a following flag as a value, so the option is left without an argument and the script aborts before doing any work.","triggerScenarios":"`--limit` as the last argument (`node scripts/convert-mdnice-images-to-cdn.js --limit`), or `--prefix --write` where the value position is occupied by another flag. Also `--domains -foo` — any next token beginning with '-' is rejected even if it was meant as a value.","commonSituations":"Forgetting the value entirely; reordering flags so a value-taking option lands right before another flag; trying to pass a value that itself starts with '-' (e.g. a relative-ish path). Note the `--opt=value` form avoids the check entirely.","solutions":["Supply the missing value: `--limit 10` or use the equals form `--limit=10`","If the intended value genuinely starts with '-', restructure it (absolute path) so it does not","Prefer the `--option=value` form to make flag/value pairing unambiguous"],"exampleFix":"// before\nnode scripts/convert-mdnice-images-to-cdn.js --limit --write\n\n// after\nnode scripts/convert-mdnice-images-to-cdn.js --limit=10 --write","handlingStrategy":"validation","validationCode":"// Pre-flight: pair every value-taking flag with a non-dash value\nconst VALUE_OPTS = [\"--env\", \"--domains\", \"--prefix\", \"--concurrency\", \"--limit\"];\nfor (let i = 0; i < args.length; i++) {\n  if (VALUE_OPTS.includes(args[i]) && (!args[i + 1] || args[i + 1].startsWith(\"-\"))) {\n    throw new Error(`${args[i]} needs a value; use ${args[i]}=value`);\n  }\n}","typeGuard":null,"tryCatchPattern":"catch (err) { if (err.message.startsWith(\"Missing value for\")) { console.error(`Supply a value: use the equals form shown in --help`); process.exit(2); } throw err; }","preventionTips":["Use the --option=value form for all value options","Never place a value-taking option last in the command","Default shell variables before use: --limit=\"${N:-50}\""],"tags":["cli","argument-parsing","usage-error"],"backgroundTag":null,"analyzedSha":"6617f5fd0b0597735bdc028f2fcd036817877327","analyzedAt":"2026-08-14T14:50:55.107Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}