itwanger/toBeBetterJavaer · error · Error
Unknown option: ${arg}
Error message
Unknown option: ${arg} What it means
Thrown by the argument parser of scripts/convert-mdnice-images-to-cdn.js when a command-line token starts with '-' but does not match any recognized flag (--write, --env, --domains, --prefix, --concurrency, --limit, --verbose, --help/-h). The parser walks argv token by token, and any leading-dash token that falls through every branch hits this guard. It exists to fail fast on typos instead of silently treating the token as a target path.
Source
Thrown at scripts/convert-mdnice-images-to-cdn.js:93
} else if (arg.startsWith("--domains=")) {
options.domains = parseList(arg.slice("--domains=".length));
} else if (arg === "--prefix") {
options.prefix = requireValue(argv, i);
i += 1;
} else if (arg.startsWith("--prefix=")) {
options.prefix = arg.slice("--prefix=".length);
} else if (arg === "--concurrency") {
options.concurrency = parsePositiveInt(requireValue(argv, i), "--concurrency");
i += 1;
} else if (arg.startsWith("--concurrency=")) {
options.concurrency = parsePositiveInt(arg.slice("--concurrency=".length), "--concurrency");
} else if (arg === "--limit") {
options.limit = parsePositiveInt(requireValue(argv, i), "--limit");
i += 1;
} else if (arg.startsWith("--limit=")) {
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;View on GitHub (pinned to 6617f5fd0b)
Solutions
- Run `node scripts/convert-mdnice-images-to-cdn.js --help` and correct the flag name to one of the supported options
- When invoking through npm, use `npm run images:cdn -- <flags>` so flags reach the script
- Remember there is no --dry-run flag: omit --write for a dry run
Example fix
// before node scripts/convert-mdnice-images-to-cdn.js --dry-run --writ // after (dry run is the default; typo fixed) node scripts/convert-mdnice-images-to-cdn.js --verbose
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: whitelist allowed flags before invoking
const ALLOWED = new Set(["--write", "verbose", "--env", "--domains", "--prefix", "--concurrency", "--limit", "--help", "-h"]);
const flags = args.filter((a) => a.startsWith("-") && !a.includes("="));
const bad = flags.filter((f) => !ALLOWED.has(f));
if (bad.length) throw new Error(`Check these flags first: ${bad.join(", ")}`); Try / catch
catch (err) { if (err.message.startsWith("Unknown option:")) { printHelp-ish guidance: run with --help; } else throw err; } Prevention
- Keep an npm script wrapper (npm run images:cdn -- <flags>) so flags are typed once
- Run with --help after upgrading the script to see the current flag set
- Prefer --opt=value forms; typos in them still hit the unknown-option guard instead of misparsing
When it happens
Trigger: Running `node scripts/convert-mdnice-images-to-cdn.js --writ` (typo), `--dry-run` (unsupported flag), or `-x`. Also `--limit 5 --dry` where the second unknown flag aborts the run. Note only tokens starting with '-' throw; non-dash tokens are pushed into options.targets as file/dir paths.
Common situations: Typoing --verbose/--write; assuming a dry-run flag exists (dry-run is the default without --write); passing an npm script flag without the `--` separator, e.g. `npm run images:cdn --write` instead of `npm run images:cdn -- --write` so npm consumes or mangles it; passing a negative-looking path.
Related errors
- Missing value for ${argv[index]}
- 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/7e79aee03baae160.
Report an issue: GitHub.