jackwener/OpenCLI · error · ArgumentError
weibo user-posts limit must be an integer between 1 and ${MA
Error message
weibo user-posts limit must be an integer between 1 and ${MAX_LIMIT} What it means
ArgumentError thrown by readLimit when the `limit` option is not an integer in [1, MAX_LIMIT] (MAX_LIMIT = 100). Empty/absent values default to 20; anything else must parse via Number() into a whole number within range. Note the thrown message interpolates MAX_LIMIT at runtime despite the literal string shown.
Source
Thrown at clis/weibo/user-posts.js:23
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { unwrapEvaluateResult } from './utils.js';
const MAX_LIMIT = 100;
const DEFAULT_LIMIT = 20;
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
function readRequiredId(raw) {
const value = String(raw ?? '').trim();
if (!value) {
throw new ArgumentError('weibo user-posts id cannot be empty');
}
return value;
}
function readLimit(raw) {
const value = raw === undefined || raw === null || raw === '' ? DEFAULT_LIMIT : Number(raw);
if (!Number.isInteger(value) || value < 1 || value > MAX_LIMIT) {
throw new ArgumentError(`weibo user-posts limit must be an integer between 1 and ${MAX_LIMIT}`);
}
return value;
}
function readDate(raw, name) {
if (raw === undefined || raw === null || raw === '') return null;
const value = String(raw).trim();
if (!DATE_RE.test(value)) {
throw new ArgumentError(`weibo user-posts ${name} must use YYYY-MM-DD`);
}
const date = new Date(`${value}T00:00:00+08:00`);
if (!Number.isFinite(date.getTime()) || value !== formatShanghaiDate(date)) {
throw new ArgumentError(`weibo user-posts ${name} must be a valid calendar date`);
}
return value;
}
function formatShanghaiDate(date) {View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and 100, e.g. `--limit 50`
- Strip whitespace/units and validate numeric config values before invoking
- Omit --limit entirely to use the default of 20
Example fix
// before weibo user-posts 12345 --limit "1,000" // after weibo user-posts 12345 --limit 100
Defensive patterns
Strategy: validation
Validate before calling
const limit = Number(rawLimit);
if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
throw new Error('limit must be an integer between 1 and 100');
}
await weiboUserPosts({ id, limit }); Type guard
function isValidLimit(v) {
return Number.isInteger(v) && v >= 1 && v <= 100;
} Try / catch
try {
await weiboUserPosts({ id, limit });
} catch (err) {
if (err instanceof ArgumentError && String(err.message).includes('limit')) {
console.error('Pass an integer between 1 and 100, or omit --limit for the default of 20.');
} else throw err;
} Prevention
- Validate/parse limit from config or env before passing it to the CLI
- Strip units, whitespace, and thousands separators from user-supplied numbers
- Remember the max is 100; omit the option for the default of 20
When it happens
Trigger: Passing `--limit 0`, `--limit 101`, `--limit abc`, `--limit 12.5`, or any non-numeric string to `weibo user-posts`.
Common situations: Copy-pasting a limit with a trailing space/unit ('20 条'); passing a float or comma-formatted number ('1,000'); setting limit from a config/env var containing garbage; assuming the cap is higher than 100.
Related errors
- --limit must be an integer between 1 and ${MAX_LIMIT}
- <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-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8c81bab7b98df948.
Report an issue: GitHub.