jackwener/OpenCLI · warning · ArgumentError
--limit must be between ${RECOMMEND_MIN_LIMIT} and ${RECOMME
Error message
--limit must be between ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${parsed} What it means
parseRecommendLimit validates the `--limit` option of the toutiao recommend CLI command. This specific throw fires only when the value IS a valid integer but falls outside the allowed range [RECOMMEND_MIN_LIMIT=1, RECOMMEND_MAX_LIMIT=50]. The library enforces this bound to keep the upstream request well-formed and avoid abusive or empty fetches.
Source
Thrown at clis/toutiao/utils.js:32
if (raw === undefined || raw === null || raw === '') return fallback;
const parsed = Number(raw);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--page must be an integer between ${ARTICLES_MIN_PAGE} and ${ARTICLES_MAX_PAGE}, got ${JSON.stringify(raw)}`);
}
if (parsed < ARTICLES_MIN_PAGE || parsed > ARTICLES_MAX_PAGE) {
throw new ArgumentError(`--page must be between ${ARTICLES_MIN_PAGE} and ${ARTICLES_MAX_PAGE}, got ${parsed}`);
}
return parsed;
}
export function parseRecommendLimit(raw, fallback = 20) {
if (raw === undefined || raw === null || raw === '') return fallback;
const parsed = Number(raw);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be an integer between ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${JSON.stringify(raw)}`);
}
if (parsed < RECOMMEND_MIN_LIMIT || parsed > RECOMMEND_MAX_LIMIT) {
throw new ArgumentError(`--limit must be between ${RECOMMEND_MIN_LIMIT} and ${RECOMMEND_MAX_LIMIT}, got ${parsed}`);
}
return parsed;
}
export function parseRecommendCategory(raw, fallback = '__all__') {
if (raw === undefined || raw === null || raw === '') return fallback;
const value = String(raw).trim();
if (!RECOMMEND_CATEGORIES.includes(value)) {
throw new ArgumentError(`--category must be one of ${RECOMMEND_CATEGORIES.join(', ')}, got ${JSON.stringify(raw)}`);
}
return value;
}
export function parseHotLimit(raw, fallback = 30) {
if (raw === undefined || raw === null || raw === '') return fallback;
const parsed = Number(raw);
if (!Number.isFinite(parsed) || !Number.isInteger(parsed)) {
throw new ArgumentError(`--limit must be an integer between ${HOT_MIN_LIMIT} and ${HOT_MAX_LIMIT}, got ${JSON.stringify(raw)}`);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and 50 for --limit (default is 20).
- Clamp the value in your script before invoking: Math.min(50, Math.max(1, n)).
- Omit --limit entirely to use the default of 20.
- If more than 50 items are needed, paginate multiple calls instead of raising the limit.
Example fix
// before toutiao recommend --limit 100 // after toutiao recommend --limit 50 # or paginate multiple calls
Defensive patterns
Strategy: validation
Validate before calling
const n = Number(raw);
if (!Number.isInteger(n) || n < 1 || n > 50) throw new RangeError(`--limit must be an integer between 1 and 50, got ${raw}`); Type guard
const isValidLimit = (v) => Number.isInteger(v) && v >= 1 && v <= 50;
Try / catch
try {
parseRecommendLimit(raw);
} catch (e) {
if (e instanceof ArgumentError) { console.error(e.message); process.exitCode = 2; }
else throw e;
} Prevention
- Clamp user input with Math.min(50, Math.max(1, n)) before invoking.
- Omit --limit to accept the default of 20.
- Paginate instead of raising the limit above 50.
When it happens
Trigger: Calling the toutiao recommend command with an integer --limit < 1 (e.g. --limit 0, --limit -5) or > 50 (e.g. --limit 100). The value passed Number() and isInteger() checks but failed the min/max comparison.
Common situations: Developers copy-paging 'fetch more' scripts and guess --limit 100 expecting more rows; scripts computing limit = pageSize * pages accidentally yield 0 when pages is 0; shell variable interpolation producing an empty-adjacent 0 value.
Related errors
- --category must be one of ${RECOMMEND_CATEGORIES.join(', ')}
- --limit must be an integer between ${HOT_MIN_LIMIT} and ${HO
- --limit must be between ${HOT_MIN_LIMIT} and ${HOT_MAX_LIMIT
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/072a86d6a16014d0.
Report an issue: GitHub.