jackwener/OpenCLI · error · ArgumentError
period must be all, lastMonth, last3Months, last6Months, las
Error message
period must be all, lastMonth, last3Months, last6Months, last12Months, a year like 2025, or YYYY-MM-DD:YYYY-MM-DD
What it means
This ArgumentError is thrown by resolvePeriod when the period argument does not match any accepted value: the literals all, lastMonth, last3Months, last6Months, last12Months, a bare 4-digit year (e.g. 2025), or an explicit range YYYY-MM-DD:YYYY-MM-DD. resolvePeriod converts the period into { startDate, endDate } for HLTV stats queries; anything else cannot be mapped to a date window. Note the input is compared exactly (after trim), so case and formatting matter.
Source
Thrown at clis/hltv/utils.js:223
return copy;
}
export function resolvePeriod(period) {
const raw = String(period ?? 'all').trim();
if (raw === 'all') return null;
const now = new Date();
if (raw === 'lastMonth') return { startDate: formatDate(addMonths(now, -1)), endDate: formatDate(now) };
if (raw === 'last3Months') return { startDate: formatDate(addMonths(now, -3)), endDate: formatDate(now) };
if (raw === 'last6Months') return { startDate: formatDate(addMonths(now, -6)), endDate: formatDate(now) };
if (raw === 'last12Months') return { startDate: formatDate(addMonths(now, -12)), endDate: formatDate(now) };
if (/^\d{4}$/.test(raw)) return { startDate: `${raw}-01-01`, endDate: `${raw}-12-31` };
if (/^\d{4}-\d{2}-\d{2}:\d{4}-\d{2}-\d{2}$/.test(raw)) {
const [startDate, endDate] = raw.split(':');
return { startDate, endDate };
}
throw new ArgumentError('period must be all, lastMonth, last3Months, last6Months, last12Months, a year like 2025, or YYYY-MM-DD:YYYY-MM-DD');
}
export function buildPlayerUrl(player) {
const { playerId, slug } = parsePlayerRef(player);
return new URL(`/player/${playerId}/${slug}`, BASE);
}
export function buildPlayerMatchesUrl(args) {
const { playerId, slug } = parsePlayerRef(args.player);
const eventType = normalizeChoice(args.eventType, 'all', EVENT_TYPES, 'eventType');
const ranking = normalizeChoice(args.ranking, 'all', RANKING_FILTERS, 'ranking');
const map = normalizeChoice(args.map, 'all', MAPS, 'map');
const version = normalizeChoice(args.version, 'both', VERSIONS, 'version');
const offset = normalizeOffset(args.offset, 0);
const period = String(args.period ?? 'all');
const event = parseEventRef(args.event);
const url = new URL(`/stats/players/matches/${playerId}/${slug}`, BASE);View on GitHub (pinned to 49907e53dc)
Solutions
- Use one of the exact literals: 'all', 'lastMonth', 'last3Months', 'last6Months', 'last12Months', or a 4-digit year '2025'.
- For custom windows, format as 'YYYY-MM-DD:YYYY-MM-DD' with zero-padded dates and a colon separator.
- Preprocess user input: trim, lowercase, and map synonyms (e.g. 'last 3 months' -> 'last3Months') before calling.
- Convert Date objects to 'YYYY-MM-DD' strings first and join with ':'.
Example fix
// before
resolvePeriod('2025-01-01/2025-06-30'); // ArgumentError
// after
resolvePeriod('2025-01-01:2025-06-30');
// or a preset
resolvePeriod('last6Months'); Defensive patterns
Strategy: validation
Validate before calling
const PERIOD_RE = /^(all|lastMonth|last3Months|last6Months|last12Months|\d{4}|\d{4}-\d{2}-\d{2}:\d{4}-\d{2}-\d{2})$/;
function isValidPeriod(p) {
return PERIOD_RE.test(String(p ?? 'all').trim());
}
if (!isValidPeriod(input)) throw new TypeError(`invalid period: ${input}`); Type guard
function isPeriod(v) {
return typeof v === 'string' && /^(all|lastMonth|last3Months|last6Months|last12Months|\d{4}|\d{4}-\d{2}-\d{2}:\d{4}-\d{2}-\d{2})$/.test(v);
} Try / catch
try {
const period = resolvePeriod(input);
} catch (err) {
if (err.name === 'ArgumentError' && err.message.startsWith('period must be')) {
console.error(`Bad --period "${input}"; use all|lastMonth|last3Months|last6Months|last12Months|YYYY|YYYY-MM-DD:YYYY-MM-DD`);
process.exitCode = 2;
} else throw err;
} Prevention
- Use a const enum/whitelist of period presets in your app and pass only those.
- Format custom ranges with padded YYYY-MM-DD joined by ':' — never '/' or '->'.
- Lowercase/alias-map user input ('last 3 months' -> 'last3Months') before calling.
- Convert Date objects to 'YYYY-MM-DD' strings before composing a range.
When it happens
Trigger: resolvePeriod('Last 3 Months') (case/spelling mismatch), resolvePeriod('30d'), resolvePeriod('2025-01'), resolvePeriod('2025-01-01') (single date without :end), resolvePeriod('2025-01-01/2025-06-30') (wrong separator — must be ':'), or a range with dates not zero-padded.
Common situations: Building CLI flags from free-text user input; translating human period names ('last quarter') without mapping to the exact enum; generating ranges with '/' or '->' separators instead of ':'; passing Date objects instead of strings (String(date) never matches).
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
- ${label} must be <= ${maxValue}
- player is required
- player must be like 3741/niko, a player URL, or a stats play
- match is required
- match must be an HLTV match, stats series, or mapstats URL
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/15fa60aff588bdb6.
Report an issue: GitHub.