jackwener/OpenCLI · error · ArgumentError
limit must be <= ${max}
Error message
limit must be <= ${max} What it means
normalizeLimit() also enforces an upper bound: values greater than max throw this ArgumentError. The cap protects the 12306 API and result rendering from unbounded queries.
Source
Thrown at clis/12306/utils.js:111
if (!DATE_RE.test(String(value ?? ''))) {
throw new ArgumentError(`date must be YYYY-MM-DD, got "${value}"`);
}
const [y, m, d] = value.split('-').map(Number);
const date = new Date(Date.UTC(y, m - 1, d));
if (date.getUTCFullYear() !== y || date.getUTCMonth() !== m - 1 || date.getUTCDate() !== d) {
throw new ArgumentError(`date "${value}" is not a real calendar date`);
}
return value;
}
export function normalizeLimit(value, defaultValue, max) {
if (value === undefined || value === null || value === '') return defaultValue;
const n = Number(value);
if (!Number.isInteger(n) || n < 1) {
throw new ArgumentError(`limit must be a positive integer (1-${max})`);
}
if (n > max) {
throw new ArgumentError(`limit must be <= ${max}`);
}
return n;
}
/** Extract Set-Cookie header values into a single `Cookie:` header string. */
export function buildCookieHeader(setCookieHeaders) {
if (!Array.isArray(setCookieHeaders) || setCookieHeaders.length === 0) return '';
return setCookieHeaders
.map((line) => line.split(';')[0])
.filter(Boolean)
.join('; ');
}
export async function fetchStationBundle(fetchImpl = fetch) {
const resp = await fetchImpl(STATION_BUNDLE_URL, {
headers: { 'User-Agent': UA },
});
if (!resp.ok) {View on GitHub (pinned to 49907e53dc)
Solutions
- Lower the limit to the command's documented maximum (read from the error message)
- Omit limit to use the default within the allowed range
- If you need more results, paginate or refine the query rather than raising the limit
Example fix
// before
await query({ limit: 500 }); // max is 100
// after
await query({ limit: 100 }); // within max Defensive patterns
Strategy: validation
Validate before calling
function isWithinLimit(v, max) {
const n = Number(v);
return Number.isInteger(n) && n >= 1 && n <= max;
}
if (!isWithinLimit(500, MAX_LIMIT)) throw new Error(`limit must be <= ${MAX_LIMIT}`); Try / catch
try {
await query({ limit });
} catch (e) {
if (e instanceof ArgumentError && e.message.startsWith('limit must be <=')) {
console.error(`Cap the limit at the documented maximum or paginate instead.`);
} else throw e;
} Prevention
- Clamp limits with Math.min(requested, max) before calling
- Read each command's max from docs/help — caps differ per command
- Paginate instead of requesting everything at once
When it happens
Trigger: Passing limit above the command's maximum, e.g. limit=1000 when the command caps results, or limit=Infinity from a computed default.
Common situations: Developers assuming there is no cap and requesting 'everything', or copying a limit valid for one command into another with a lower max.
Related errors
- limit must be a positive integer (1-${max})
- Unknown 12306 station telecode "${trimmed}"
- Unknown 12306 station "${trimmed}"
- date must be YYYY-MM-DD, got "${value}"
- date "${value}" is not a real calendar date
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7b371efa835ec8fd.
Report an issue: GitHub.