jackwener/OpenCLI · error · ArgumentError
${label} must be <= ${maxValue}
Error message
${label} must be <= ${maxValue} What it means
normalizeLimit validates a user-supplied limit/pageSize option before building an HLTV API request. It throws ArgumentError when the value is not a positive integer, and this specific error when the value exceeds the command's configured maxValue cap. The cap exists because HLTV's endpoints reject or truncate requests with excessively large limits.
Source
Thrown at clis/hltv/utils.js:67
cache: 'de_cache',
cobblestone: 'de_cobblestone',
season: 'de_season',
train: 'de_train',
tuscan: 'de_tuscan',
vertigo: 'de_vertigo',
};
export const VERSIONS = {
both: null,
cs2: 'CS2',
csgo: 'CSGO',
};
export function normalizeLimit(value, defaultValue, maxValue, label = 'limit') {
const raw = value ?? defaultValue;
const n = Number(raw);
if (!Number.isInteger(n) || n <= 0) throw new ArgumentError(`${label} must be a positive integer`);
if (n > maxValue) throw new ArgumentError(`${label} must be <= ${maxValue}`);
return n;
}
export function normalizeOffset(value, defaultValue = 0) {
const raw = value ?? defaultValue;
const n = Number(raw);
if (!Number.isInteger(n) || n < 0) throw new ArgumentError('offset must be a non-negative integer');
if (n % 100 !== 0) throw new ArgumentError('offset must be a multiple of 100');
return n;
}
export function normalizeChoice(value, defaultValue, choices, label) {
const raw = String(value ?? defaultValue);
if (!Object.prototype.hasOwnProperty.call(choices, raw)) {
throw new ArgumentError(`${label} must be one of: ${Object.keys(choices).join(', ')}`);
}
return raw;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Lower the limit to the command's documented maximum (check the option help for maxValue)
- If more results are needed, page through with offset increments instead of one large limit
- Ensure the value passed is a number, not a string like '500' that may fail the integer check first
Example fix
// before hltv top20 --limit 1000 // after hltv top20 --limit 100 # or page: --limit 100 --offset 100
Defensive patterns
Strategy: validation
Validate before calling
function validateLimit(v, max) { const n = Number(v); return Number.isInteger(n) && n > 0 && n <= max; }
if (!validateLimit(opts.limit, 100)) throw new Error(`limit must be a positive integer <= 100`); Type guard
const isLimit = (v, max) => Number.isInteger(Number(v)) && Number(v) > 0 && Number(v) <= max;
Try / catch
try {
await hltv.top20({ limit });
} catch (e) {
if (e.name === 'ArgumentError') { console.error(`Bad --limit: ${e.message}`); process.exitCode = 2; }
else throw e;
} Prevention
- Clamp the limit before calling: limit = Math.min(Number(limit) || 100, max)
- Page with offset instead of raising the limit
- Read the command's --help to learn the per-command maximum
When it happens
Trigger: Passing a limit larger than the command's max (e.g. --limit 500 where max is 100), or programmatically calling limit/normalizeLimit(value, default, maxValue) with maxValue exceeded.
Common situations: Users copy a limit from another API's docs assuming unlimited paging; scripts that guess page sizes; misremembering the CLI's documented cap for a specific subcommand.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- 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
- archive search limit must be <= 100
- archive search query must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a64a74c704e1bd87.
Report an issue: GitHub.