jackwener/OpenCLI · error · ArgumentError
limit must be <= ${MAX_LIMIT}
Error message
limit must be <= ${MAX_LIMIT} What it means
normalizeLimit also caps --limit at MAX_LIMIT (50) and throws an ArgumentError when a valid positive integer exceeds the cap, with an example suggesting --limit 50. This keeps scraping requests bounded so the command doesn't over-fetch or hammer the page.
Source
Thrown at clis/aibase/news.js:15
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();
return text && href && !href.endsWith('/zh/daily') && !href.endsWith('/zh/daily/');
});
if (anchors.length === 0) {View on GitHub (pinned to 49907e53dc)
Solutions
- Use --limit 50 (the maximum) instead.
- Omit --limit (default 20) if fewer items suffice.
- Note the daily page only exposes a bounded set of articles anyway; there are rarely more than 50 rows to return.
Example fix
// before opencli aibase news --limit 100 // after opencli aibase news --limit 50
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(limitArg);
if (Number.isInteger(n) && n > 50) throw new Error('--limit max is 50'); Type guard
function isWithinCap(v, cap = 50) {
return typeof v === 'number' && Number.isInteger(v) && v > 0 && v <= cap;
} Try / catch
try {
await runCommand(['aibase', 'news', '--limit', String(n)]);
} catch (e) {
if (e instanceof ArgumentError && e.message.startsWith('limit must be <=')) {
await runCommand(['aibase', 'news', '--limit', '50']);
} else throw e;
} Prevention
- Clamp page sizes to the command's documented max (50 here)
- Don't reuse generic page-size constants (e.g. 100) across commands
- Omit --limit to accept the default 20
- Remember the daily page has a naturally bounded row count
When it happens
Trigger: Running `opencli aibase news --limit 51` or higher (e.g. --limit 100, --limit 1000).
Common situations: Users wanting 'all' items passing a large number, scripts using a generic page-size (100) that exceeds this command's max, and confusion with other commands whose limits are uncapped.
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
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
- --from and --to must differ; both resolved to ${fromStation.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a91d5086c85da777.
Report an issue: GitHub.