jackwener/OpenCLI · warning · ArgumentError
xianyu ${label} must be an integer between 1 and ${maxValue}
Error message
xianyu ${label} must be an integer between 1 and ${maxValue} What it means
normalizeLimit validates numeric limit parameters for xianyu IM commands. It throws ArgumentError when the value is not a pure digit string, or is outside 1..maxValue (default MAX_INBOX_LIMIT, MAX_MESSAGE_LIMIT=200 for messages).
Source
Thrown at clis/xianyu/im.js:12
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
export const DEFAULT_INBOX_LIMIT = 20;
export const MAX_INBOX_LIMIT = 100;
export const DEFAULT_MESSAGE_LIMIT = 50;
export const MAX_MESSAGE_LIMIT = 200;
export function normalizeLimit(value, defaultValue = DEFAULT_INBOX_LIMIT, maxValue = MAX_INBOX_LIMIT, label = 'limit') {
const raw = String(value ?? '').trim();
if (!raw) return defaultValue;
if (!/^\d+$/.test(raw)) {
throw new ArgumentError(`xianyu ${label} must be an integer between 1 and ${maxValue}`);
}
const n = Number(raw);
if (!Number.isSafeInteger(n) || n < 1 || n > maxValue) {
throw new ArgumentError(`xianyu ${label} must be an integer between 1 and ${maxValue}`);
}
return n;
}
export function normalizeRank(value) {
const raw = String(value ?? '').trim();
if (!raw) return 0;
if (!/^\d+$/.test(raw)) {
throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');
}
const n = Number(raw);
if (!Number.isSafeInteger(n) || n < 1) {
throw new ArgumentError('xianyu rank must be a positive integer from xianyu inbox');
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer string/number between 1 and the applicable max (200 for messages)
- Omit the parameter to use the default inbox limit
- Clamp or validate the value before calling the command
- For larger paging needs, use pagination instead of raising the limit
Example fix
// before
await xianyuInbox({ limit: 500 }); // throws
// after
await xianyuInbox({ limit: Math.min(500, 200) }); // clamp to max Defensive patterns
Strategy: validation
Validate before calling
function isValidLimit(v, max = 200) {
return /^\d+$/.test(String(v ?? '')) && Number(v) >= 1 && Number(v) <= max;
} Type guard
function isPositiveIntString(v) {
return typeof v === 'string' && /^\d+$/.test(v) && Number.isSafeInteger(Number(v)) && Number(v) >= 1;
} Try / catch
try {
await xianyuInbox({ limit });
} catch (e) {
if (e?.name === 'ArgumentError' && /must be an integer between/.test(e.message)) {
return xianyuInbox({ limit: 50 }); // sane default
}
throw e;
} Prevention
- Clamp user input: Math.min(Math.max(1, n), 200)
- Use integers, never floats or numeric words
- Omit the parameter to accept the default
When it happens
Trigger: Calling a xianyu limit-taking command with limit='abc', limit='0', limit='201', limit='-5', limit='1.5', or an empty-but-non-default value like ' ' that fails the regex after trim.
Common situations: Passing a float from upstream parsing; passing 0 to mean 'no limit'; exceeding MAX_MESSAGE_LIMIT=200 for message fetches; string vs number mixing from CLI argv.
Related errors
- xianyu rank must be a positive integer from xianyu inbox
- ${label} cannot be empty
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/28ff8160a87648b6.
Report an issue: GitHub.