itwanger/toBeBetterJavaer · error · Error
Missing value for ${argv[index]}
Error message
Missing value for ${argv[index]} What it means
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.
Source
Thrown at scripts/convert-mdnice-images-to-cdn.js:109
options.limit = parsePositiveInt(arg.slice("--limit=".length), "--limit");
} else if (arg.startsWith("-")) {
throw new Error(`Unknown option: ${arg}`);
} else {
options.targets.push(path.resolve(ROOT_DIR, arg));
}
}
if (options.targets.length === 0) {
options.targets.push(DEFAULT_TARGET);
}
return options;
}
function requireValue(argv, index) {
const value = argv[index + 1];
if (!value || value.startsWith("-")) {
throw new Error(`Missing value for ${argv[index]}`);
}
return value;
}
function parseList(value) {
return value
.split(",")
.map((item) => item.trim())
.filter(Boolean);
}
function parsePositiveInt(value, optionName) {
const parsed = Number.parseInt(value, 10);
if (!Number.isFinite(parsed) || parsed <= 0) {
throw new Error(`${optionName} must be a positive integer`);
}
return parsed;
}View on GitHub (pinned to 6617f5fd0b)
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
Example fix
// before node scripts/convert-mdnice-images-to-cdn.js --limit --write // after node scripts/convert-mdnice-images-to-cdn.js --limit=10 --write
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: pair every value-taking flag with a non-dash value
const VALUE_OPTS = ["--env", "--domains", "--prefix", "--concurrency", "--limit"];
for (let i = 0; i < args.length; i++) {
if (VALUE_OPTS.includes(args[i]) && (!args[i + 1] || args[i + 1].startsWith("-"))) {
throw new Error(`${args[i]} needs a value; use ${args[i]}=value`);
}
} Try / catch
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; } Prevention
- 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}"
When it happens
Trigger: `--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.
Common situations: 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.
Related errors
- Unknown option: ${arg}
- Unknown option: ${arg}
- --route and --dir must be used together
- Missing value for ${argv[index]}
- ${optionName} must be a positive integer
AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14).
Data as JSON: /api/errors/fd9bd6e0a1c18dba.
Report an issue: GitHub.