jackwener/OpenCLI · error · ArgumentError
${label} must be an integer between ${min} and ${max}, got $
Error message
${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(raw)} What it means
parseBoundedInteger validates the raw --timeout/--source-limit style option in the xiaohongshu ask command. It throws this ArgumentError when the value is neither a number nor a digit-only string — i.e. it cannot be interpreted as an integer at all. Note the message prints JSON.stringify(raw) while the type checks test `value` (raw with the default applied); a non-numeric, non-null raw always lands here.
Source
Thrown at clis/xiaohongshu/ask.js:34
'answer',
'source_count',
'source_total_text',
'sources_summary',
'sources',
'warning',
'message_id',
'conversation_id',
];
function parseBoundedInteger(raw, defaultValue, min, max, label) {
const value = raw ?? defaultValue;
let parsed;
if (typeof value === 'number') {
parsed = value;
} else if (typeof value === 'string' && /^\d+$/.test(value)) {
parsed = Number(value);
} else {
throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(raw)}`);
}
if (!Number.isInteger(parsed) || parsed < min || parsed > max) {
throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(raw)}`);
}
return parsed;
}
export function parseAskTimeout(raw) {
return parseBoundedInteger(raw, 90, 1, 180, '--timeout');
}
export function parseAskLimit(raw) {
return parseBoundedInteger(raw, 10, 1, 50, '--source-limit');
}
function cleanText(value) {
return String(value ?? '')
.replace(/<[^>]+>/g, '')View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a plain non-negative integer: --timeout 120, --source-limit 5
- Remove units/suffixes ('90s' → '90') and any sign or decimals
- Check the config file/env value feeding the option is a numeric string or number
- Ensure the value is within 1–180 for --timeout and 1–50 for --source-limit (out-of-range hits the sibling throw at line 37)
Example fix
// before opencli xiaohongshu ask --timeout 90s "query" // after opencli xiaohongshu ask --timeout 90 "query"
Defensive patterns
Strategy: validation
Validate before calling
function isValidIntOption(v, min, max) {
const n = typeof v === 'string' && /^\d+$/.test(v) ? Number(v) : v;
return Number.isInteger(n) && n >= min && n <= max;
}
if (opts.timeout != null && !isValidIntOption(opts.timeout, 1, 180)) {
throw new Error('--timeout must be an integer 1-180');
} Type guard
function isBoundedInt(v, min, max) {
const n = typeof v === 'string' && /^\d+$/.test(v) ? Number(v) : v;
return typeof n === 'number' && Number.isInteger(n) && n >= min && n <= max;
} Try / catch
try {
await xiaohongshuAsk({ query, timeout: opts.timeout });
} catch (e) {
if (e.name === 'ArgumentError' && /must be an integer between/.test(e.message)) {
console.error('Bad flag value:', e.message, '— pass a plain integer, e.g. --timeout 120');
} else throw e;
} Prevention
- Pass CLI flags as plain integers without units or signs
- Reject non-numeric strings in wrapper scripts before invoking the CLI
- Remember the regex only accepts digit strings — negatives and decimals always fail
- Defaults are applied only for null/undefined, not for invalid values
When it happens
Trigger: Passing --timeout or --source-limit values like 'abc', '1.5', '-5', '' (empty string), '90s', or true/false to the xiaohongshu ask command.
Common situations: Shell quoting issues passing '90s' or a duration with units; negative numbers (regex ^\d+$ rejects the minus sign); decimal numbers; a config file supplying a boolean or object instead of a number/string.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- query is required
- xiaohongshu/follow: invalid profile URL
- xiaohongshu/follow: profile URL must be an exact https://*.x
- xiaohongshu/follow: profile URL must be /user/profile/<userI
- xiaohongshu/follow: user-id must be a Xiaohongshu user ID (e
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f81dfb1c8a34a93c.
Report an issue: GitHub.