jackwener/OpenCLI · error · InvalidArgumentError
--${label} must be a positive integer (got "${val}")
Error message
--${label} must be a positive integer (got "${val}") What it means
Screenshot dimension options (e.g. --width/--height for screenshots) must be positive integers. parseScreenshotDim validates with /^\d+$/ and throws a commander InvalidArgumentError when the value contains non-digit characters. This is the format-failure branch (the value must be a string of digits).
Source
Thrown at src/cli.ts:764
if (typeof targetId === 'string' && targetId.trim()) return targetId.trim();
const tab = opts instanceof Command ? opts.opts().tab : opts?.tab;
if (typeof tab === 'string' && tab.trim()) return tab.trim();
return undefined;
}
function parsePositiveIntOption(val: string | undefined, label: string, fallback: number): number {
if (val === undefined) return fallback;
const parsed = parseInt(val, 10);
if (Number.isNaN(parsed) || parsed <= 0) {
console.error(`[cli] Invalid ${label}="${val}", using default ${fallback}`);
return fallback;
}
return parsed;
}
function parseScreenshotDim(val: string, label: string): number {
if (!/^\d+$/.test(val)) {
throw new InvalidArgumentError(`--${label} must be a positive integer (got "${val}")`);
}
const parsed = parseInt(val, 10);
if (parsed <= 0) {
throw new InvalidArgumentError(`--${label} must be a positive integer (got "${val}")`);
}
return parsed;
}
function applyVerbose(opts: { verbose?: boolean }): void {
if (opts.verbose) process.env.OPENCLI_VERBOSE = '1';
}
function formatChildCommandSummary(command: Command): string {
return [...new Set(command.commands.map(child => child.name()))]
.sort((a, b) => a.localeCompare(b))
.join(', ');
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Pass bare digits only: --width 1280 --height 720
- Remove units or suffixes (px, %, rem)
- Split comma-joined sizes into separate flags
- Quote the value if your shell mangles it, but keep it digit-only
Example fix
// before opencli browser my-session screenshot --width 1280px // after opencli browser my-session screenshot --width 1280
Defensive patterns
Strategy: validation
Validate before calling
function assertPositiveIntString(label: string, v: string): void {
if (!/^\d+$/.test(v)) throw new Error(`--${label} must be a positive integer, got: ${JSON.stringify(v)}`);
}
assertPositiveIntString('width', widthArg); Type guard
function isDigitString(v: string): boolean {
return /^\d+$/.test(v);
} Try / catch
try {
await run(['opencli', 'browser', session, 'screenshot', '--width', w]);
} catch (e) {
if (String((e as Error).message).includes('must be a positive integer')) {
console.error(`Bad dimension value: ${w}. Use bare positive integers, e.g. 1280.`);
}
throw e;
} Prevention
- Pass bare digits only — no units (px, %), decimals, or thousands separators
- When building flags programmatically, coerce with Number() and validate > 0 before stringifying
- Keep width/height as separate flags rather than one combined value
- Document dimension flags in script templates with example values
When it happens
Trigger: Passing values like `--width 12.5`, `--width 100px`, `--width abc`, `--width ''`, or negative numbers like `--width -50` (the '-' fails the digit regex).
Common situations: Users appending units (px, %) to the value; copying CSS-style fractional sizes; shells interpreting a leading dash; pasting '1280,720' instead of two flags.
Related errors
- ARGUMENT
- ${label} is required
- ${label} must be a positive integer
- ${label} must be <= ${maxValue}
- ${label} must be a numeric ID
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/15bd85551cfa8e63.
Report an issue: GitHub.