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

  1. Use one of the exact literals: 'all', 'lastMonth', 'last3Months', 'last6Months', 'last12Months', or a 4-digit year '2025'.
  2. For custom windows, format as 'YYYY-MM-DD:YYYY-MM-DD' with zero-padded dates and a colon separator.
  3. Preprocess user input: trim, lowercase, and map synonyms (e.g. 'last 3 months' -> 'last3Months') before calling.
  4. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/15fa60aff588bdb6. Report an issue: GitHub.