jackwener/OpenCLI · error · ArgumentError
limit must be <= ${MAX_LIMIT}
Error message
limit must be <= ${MAX_LIMIT} What it means
normalizeLimit validates the --limit flag for the `uisdc news` command. When the requested limit exceeds MAX_LIMIT, it throws an ArgumentError explaining the ceiling, because fetching unbounded rows would be wasteful and unstable. The error message includes a ready-to-copy example using the maximum allowed value.
Source
Thrown at clis/uisdc/news.js:15
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError, getErrorMessage } from '@jackwener/opencli/errors';
const UISDC_NEWS_URL = 'https://www.uisdc.com/news';
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 uisdc news --limit ${DEFAULT_LIMIT}`);
}
if (limit > MAX_LIMIT) {
throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli uisdc news --limit ${MAX_LIMIT}`);
}
return limit;
}
function normalizeText(value) {
return String(value ?? '').replace(/\s+/g, ' ').trim();
}
function buildExtractUisdcNewsJs() {
return `
(() => {
const cards = Array.from(document.querySelectorAll(
'.news-list > .news-item:first-child > .item-content > .dubao-items > .dubao-item'
));
if (cards.length === 0) {
return {
ok: false,
reason: 'selector-missing',View on GitHub (pinned to 49907e53dc)
Solutions
- Lower the --limit value to MAX_LIMIT or below
- Run `opencli uisdc news --limit <MAX_LIMIT>` as shown in the error's example hint
- Check the constant MAX_LIMIT at the top of clis/uisdc/news.js for the exact ceiling
Example fix
// before opencli uisdc news --limit 500 // after opencli uisdc news --limit 20 # assume MAX_LIMIT = 20
Defensive patterns
Strategy: validation
Validate before calling
function safeLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max ? n : null; }
const limit = safeLimit(myLimit, 20); if (limit === null) limit = DEFAULT_LIMIT; Type guard
function isValidLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max; } Try / catch
try { const rows = await run(); } catch (e) { if (e.name === 'ArgumentError') { console.error(e.message, e.hint); process.exitCode = 2; } else throw e; } Prevention
- Clamp user input with Math.min(Math.max(1, n), MAX_LIMIT) instead of passing raw values
- Read the constant MAX_LIMIT from the CLI source before scripting large batch runs
- Use the error's example hint, which already shows a valid limit
When it happens
Trigger: Running `opencli uisdc news --limit` with a number greater than MAX_LIMIT (e.g. --limit 100 when MAX_LIMIT is lower). normalizeLimit is called from the limit handler before any page load.
Common situations: Users assuming the CLI caps silently instead of erroring; scripts parameterized with a large default limit; copying --limit values from other commands with higher ceilings.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- archive search limit must be <= 100
- coingecko derivatives limit must be <= 500
- 'limit', 'must be a positive integer ≤ 200'
- --limit must be between 1 and 100, got ${parsed}
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4caccc8a9b056eb8.
Report an issue: GitHub.