jackwener/OpenCLI · error · ArgumentError
pubmed ${label} must be <= ${maxValue}
Error message
pubmed ${label} must be <= ${maxValue} What it means
requireBoundedInt's final check: the validated integer is compared to the caller-provided maxValue ceiling (e.g. max results per request). Exceeding it throws ArgumentError 'pubmed <label> must be <= <maxValue>'.
Source
Thrown at clis/pubmed/utils.js:37
const pmid = requireText(value, label);
if (!/^\d+$/.test(pmid)) {
throw new ArgumentError(`pubmed ${label} must be a numeric PMID`, 'Example: 37780221');
}
return pmid;
}
export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const text = String(raw).trim();
if (!/^\d+$/.test(text)) {
throw new ArgumentError(`pubmed ${label} must be a positive integer`);
}
const n = Number(text);
if (!Number.isSafeInteger(n) || n < 1) {
throw new ArgumentError(`pubmed ${label} must be a positive integer`);
}
if (n > maxValue) {
throw new ArgumentError(`pubmed ${label} must be <= ${maxValue}`);
}
return n;
}
export function requireYear(value, label) {
if (value === undefined || value === null || value === '') {
return undefined;
}
const year = requireBoundedInt(value, 1900, 3000, label);
if (year < 1800) {
throw new ArgumentError(`pubmed ${label} must be >= 1800`);
}
return year;
}
export function requireChoice(value, choices, label, defaultValue) {
const text = String(value ?? defaultValue).trim();
if (!choices.includes(text)) {View on GitHub (pinned to 49907e53dc)
Solutions
- Lower the limit to the value stated in the error message
- Paginate: issue multiple narrower searches instead of one huge limit
- Check the command's --help for the exact maximum
Example fix
// before --limit 100000 // after --limit 100 // paginate for more
Defensive patterns
Strategy: validation
Validate before calling
const MAX = 100; // per command docs
if (Number(limit) > MAX) {
console.warn(`--limit ${limit} exceeds max ${MAX}; clamping`);
limit = MAX;
} Type guard
function isWithinMax(v, max) {
const n = Number(v);
return Number.isSafeInteger(n) && n >= 1 && n <= max;
} Try / catch
try {
await pubmedSearch(query, { limit });
} catch (err) {
const m = /must be <= (\d+)/.exec(err.message ?? '');
if (err instanceof ArgumentError && m) {
await pubmedSearch(query, { limit: Number(m[1]) }); // retry at max
} else { throw err; }
} Prevention
- Read the error message — it states the exact maximum
- Paginate instead of raising the limit
- Clamp user-supplied page sizes against the documented cap before invoking
When it happens
Trigger: Requesting more results than the command allows, e.g. `--limit 100000` when the cap is lower.
Common situations: Trying to fetch an entire large result set in one call, forwarding raw user-supplied page sizes, misremembering the documented cap.
Related errors
- bilibili comments limit must be an integer between 1 and ${M
- bilibili comments parent must be a positive integer rpid
- boss ${name} must be <= ${max}
- 标题不能超过 30 字
- 正文不能超过 1000 字
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2f4566d98b2b4cc4.
Report an issue: GitHub.