itwanger/toBeBetterJavaer · error · Error
${optionName} must be a positive integer
Error message
${optionName} must be a positive integer What it means
Thrown by parsePositiveInt() in scripts/convert-mdnice-images-to-cdn.js when the value passed to --concurrency or --limit is not a base-10 integer greater than zero. Number.parseInt is applied, then the result is rejected if it is non-finite or <= 0. This guards worker-pool sizing and batch limits against zero, negative, fractional, or non-numeric input.
Source
Thrown at scripts/convert-mdnice-images-to-cdn.js:124
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;
}
function loadEnv(envFile) {
if (!fs.existsSync(envFile)) {
return {};
}
const env = {};
const content = fs.readFileSync(envFile, "utf8");
for (const line of content.split(/\r?\n/)) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) {
continue;
}
const equalsIndex = trimmed.indexOf("=");
if (equalsIndex === -1) {View on GitHub (pinned to 6617f5fd0b)
Solutions
- Pass a positive integer: `--concurrency 4` or `--limit 100`
- For 'no limit', omit --limit entirely (default is null = unlimited)
- Check the shell variable actually expands: `--limit="${N}"` with N unset becomes an empty value — default it first: `--limit="${N:-100}"`
Example fix
// before node scripts/convert-mdnice-images-to-cdn.js --limit=0 // after (omit --limit for unlimited, or pass a positive count) node scripts/convert-mdnice-images-to-cdn.js --limit=100
Defensive patterns
Strategy: validation
Validate before calling
function isPositiveInt(v) { return /^\d+$/.test(String(v)) && Number.parseInt(v, 10) > 0; }
if (!isPositiveInt(limit)) throw new Error("--limit must be a positive integer"); Type guard
const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0 && /^\d+$/.test(String(v));
Try / catch
catch (err) { if (err.message.endsWith("must be a positive integer")) { /* re-ask user / clamp to default */ } else throw err; } Prevention
- Validate numeric CLI inputs in the calling wrapper before spawning the script
- Omit --limit when unlimited is intended instead of passing 0
- Quote values from variables and default them
When it happens
Trigger: `--concurrency 0`, `--limit -5`, `--concurrency 2.5` (parseInt yields 2, so this one actually passes), `--concurrency abc` (NaN), or `--limit=` (empty string -> NaN). Strictly: any value where parseInt is NaN or the parsed value is <= 0.
Common situations: Copy-pasting `--concurrency 0` hoping to disable the limit; passing an empty value via `--limit=`; passing 1e3-style or comma-formatted numbers; a shell variable that expands to nothing.
Related errors
- Unknown option: ${arg}
- Missing value for ${argv[index]}
- Path not found: ${target}
- Unknown option: ${arg}
- --route and --dir must be used together
AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14).
Data as JSON: /api/errors/87062858b06f745a.
Report an issue: GitHub.