jackwener/OpenCLI · error · ArgumentError
limit must be a positive integer
Error message
limit must be a positive integer
What it means
normalizeLimit in clis/aibase/news.js validates the --limit argument for the aibase news command and throws an ArgumentError when the value is not a positive integer (zero, negative, non-numeric, or fractional). The error carries an example usage string showing the default limit (20).
Source
Thrown at clis/aibase/news.js:12
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError, getErrorMessage } from '@jackwener/opencli/errors';
const AIBASE_DAILY_URL = 'https://www.aibase.com/zh/daily';
const DEFAULT_LIMIT = 20;
const MAX_LIMIT = 50;
function normalizeLimit(value) {
const raw = value ?? DEFAULT_LIMIT;
const limit = Number(raw);
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('limit must be a positive integer', `Example: opencli aibase news --limit ${DEFAULT_LIMIT}`);
}
if (limit > MAX_LIMIT) {
throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli aibase news --limit ${MAX_LIMIT}`);
}
return limit;
}
function normalizeText(value) {
return String(value ?? '').replace(/\s+/g, ' ').trim();
}
function buildExtractAibaseNewsJs() {
return `
(() => {
const anchors = Array.from(document.querySelectorAll('.bg-white .grid a[href], a[href*="/zh/daily/"]'))
.filter((anchor) => {
const href = anchor.getAttribute('href') || '';
const text = (anchor.innerText || anchor.textContent || '').trim();View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a positive integer between 1 and 50, e.g. opencli aibase news --limit 20.
- Omit --limit to use the default of 20.
- If passing programmatically, validate first: Number.isInteger(Number(v)) && Number(v) > 0.
Example fix
// before opencli aibase news --limit 0 // after opencli aibase news --limit 20
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(limitArg);
if (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer'); Type guard
function isPositiveInt(v) {
return typeof v === 'number' && Number.isInteger(v) && v > 0;
} Try / catch
try {
await runCommand(['aibase', 'news', '--limit', String(n)]);
} catch (e) {
if (e instanceof ArgumentError && e.message === 'limit must be a positive integer') {
console.error('Invalid --limit; falling back to default 20');
} else throw e;
} Prevention
- Validate CLI ints with Number.isInteger before passing
- Never pass 0 or negatives expecting 'unlimited' behavior
- Avoid locale-formatted numeric strings
- Quote shell variables used in flags
When it happens
Trigger: Running `opencli aibase news --limit 0`, `--limit -3`, `--limit abc`, or `--limit 2.5`.
Common situations: Typing 0 assuming it means 'unlimited', scripts substituting empty strings into the flag, locale-formatted numbers ('2,5' or '10件'), and copy-paste errors with trailing characters.
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 a non-negative integer, got ${JSON.stringif
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
- bloomberg businessweek --limit must be an integer between 1
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cb8309321cc5f648.
Report an issue: GitHub.