jackwener/OpenCLI · error · ArgumentError
${label} must be a positive integer
Error message
${label} must be a positive integer What it means
Thrown by requirePositiveInt in clis/lobsters/read.js:33 when a numeric CLI argument that must be >= 1 is not a positive integer. Used for --limit (top-level comments), --depth (max reply depth), and --replies (max replies per level). ArgumentError indicates caller input error, not a network problem.
Source
Thrown at clis/lobsters/read.js:33
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
const LOBSTERS_STORY_BASE = 'https://lobste.rs/s';
async function fetchStory(shortId) {
const res = await fetch(`${LOBSTERS_STORY_BASE}/${shortId}.json`);
if (res.status === 404) {
throw new EmptyResultError(`lobsters/${shortId}`, 'Story not found');
}
if (!res.ok) {
throw new CommandExecutionError(`Lobsters API HTTP ${res.status} for story ${shortId}`, 'Check the short id');
}
return res.json();
}
function requirePositiveInt(value, label) {
if (!Number.isInteger(value) || value <= 0) {
throw new ArgumentError(`${label} must be a positive integer`);
}
return value;
}
function requireMinInt(value, min, label) {
if (!Number.isInteger(value) || value < min) {
throw new ArgumentError(`${label} must be an integer >= ${min}`);
}
return value;
}
/** Lobsters returns comment text as a small HTML subset — convert to plain text. */
function htmlToText(html) {
if (!html) return '';
return String(html)
.replace(/<p>/gi, '\n\n')
.replace(/<\/p>/gi, '')
.replace(/<br\s*\/?>/gi, '\n')View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive whole number, e.g. `lobsters read 6cmh6h --limit 25 --depth 2 --replies 5`
- Check wrapper scripts aren't passing 0/null for these flags; omit the flag to use defaults (25/2/5)
- Coerce strings to integers with Number.parseInt before invoking if calling programmatically
- Use --depth 1 if you want no replies — 1, not 0
Example fix
// before lobsters read 6cmh6h --depth 0 // after lobsters read 6cmh6h --depth 1
Defensive patterns
Strategy: validation
Validate before calling
function assertPositiveInt(v, label) {
if (!Number.isInteger(v) || v <= 0) throw new Error(`${label} must be a positive integer`);
}
assertPositiveInt(limit, 'limit');
assertPositiveInt(depth, 'depth');
assertPositiveInt(replies, 'replies'); Type guard
function isPositiveInt(v) {
return Number.isInteger(v) && v > 0;
} Try / catch
try {
await run(['lobsters', 'read', id, '--limit', String(limit)]);
} catch (e) {
if (e.message.includes('must be a positive integer')) {
console.error(`Fix ${e.message.split(' ')[0]} flag`);
}
throw e;
} Prevention
- Rely on defaults (limit 25, depth 2, replies 5) instead of hand-set values
- Coerce/parse flags with Number.parseInt and validate before invoking
- Never pass 0 or negative values expecting 'unlimited' — use --depth 1 for no replies
- Add pre-flight checks in wrapper scripts
When it happens
Trigger: Passing `--limit 0`, `--depth -1`, `--replies abc`, or a non-integer like `--limit 2.5` (or a value parsed as non-int). Any of limit/depth/replies failing Number.isInteger or being <= 0 raises it.
Common situations: Typing negative numbers intending 'no limit'; copying float values from scripts; passing string flags in wrapper scripts where type coercion doesn't happen; forgetting defaults when args come from a JSON pipeline with null/0 values.
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
- ${label} must be an integer >= ${min}
- Invalid Lobsters short_id: ${args.id}
- INVALID_ARGUMENT
- INVALID_ARGUMENT
- Collection name cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6b963e54c3798e5b.
Report an issue: GitHub.