jackwener/OpenCLI · error · ArgumentError
${label} must be a positive integer
Error message
${label} must be a positive integer What it means
normalizePositiveInteger validates numeric CLI options (like --min-count) before use, coercing via Number() and requiring a positive integer result. It throws ArgumentError when the value is missing-but-no-default, non-numeric, zero, negative, or fractional. This ensures downstream loops that fetch N images never run with nonsensical counts.
Source
Thrown at clis/grok/image.js:18
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as crypto from 'node:crypto';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, TimeoutError } from '@jackwener/opencli/errors';
import { GROK_URL, isOnGrok, normalizeBooleanFlag } from './utils.js';
const SESSION_HINT = 'Likely login/auth/challenge/session issue in the existing grok.com browser session.';
/**
* Validate a positive-integer arg without silently flooring/clamping.
* Throws ArgumentError on `0`, negatives, non-integers, or non-numeric input.
*/
function normalizePositiveInteger(value, defaultValue, label) {
const raw = value ?? defaultValue;
const n = Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new ArgumentError(`${label} must be a positive integer`);
}
return n;
}
function dedupeBySrc(images) {
const seen = new Set();
const out = [];
for (const img of images) {
if (!img.src || seen.has(img.src)) continue;
seen.add(img.src);
out.push(img);
}
return out;
}
function imagesSignature(images) {
return images.map(i => i.src).sort().join('|');
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive whole number (>= 1) for the option, or omit it to use the default.
- If 'no minimum' is intended, drop the flag rather than passing 0.
- Quote values in the shell so empty/whitespace values don't slip through as ''.
Example fix
// before node cli.js image --min-count 0 // after node cli.js image --min-count 3 # or omit the flag entirely
Defensive patterns
Strategy: validation
Validate before calling
function isValidPositiveInteger(v) {
const n = Number(v);
return Number.isInteger(n) && n > 0;
}
const minCount = process.env.MIN_COUNT;
if (minCount !== undefined && !isValidPositiveInteger(minCount)) {
throw new Error(`min-count must be a positive integer, got: ${minCount}`);
} Type guard
function isPositiveInteger(v) {
return typeof v === 'number' && Number.isInteger(v) && v > 0;
} Try / catch
try {
await cli.image({ minCount });
} catch (e) {
if (e instanceof ArgumentError && /positive integer/.test(e.message)) {
console.error(`Bad --min-count value: ${JSON.stringify(minCount)}`);
process.exitCode = 2;
} else throw e;
} Prevention
- Validate numeric CLI inputs with an integer check before invoking the command.
- Treat 0 as 'flag omitted', not 'no minimum'.
- Use ${VAR:?msg} shell expansion to catch unset variables feeding numeric flags.
When it happens
Trigger: Calling minCount with --min-count=0, --min-count=-3, --min-count=2.5, --min-count=abc, or an empty string with no default configured.
Common situations: Typo in the CLI flag value, shell passing an empty string for an unset variable, or a user trying to say 'no minimum' with 0 instead of omitting the flag.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- bilibili comments limit must be an integer between 1 and ${M
- bilibili comments parent must be a positive integer rpid
- boss ${name} must be <= ${max}
- prompt is required
- pubmed ${label} must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/92277b26c2c25ee4.
Report an issue: GitHub.