jackwener/OpenCLI · error · ArgumentError

match is required

Error message

match is required

What it means

This ArgumentError is thrown by normalizeMatchUrl when the match value is empty after String(value ?? '').trim(). normalizeMatchUrl is the entry point that turns any HLTV match reference (match URL, stats series URL, or mapstats URL) into a normalized URL object; without a non-empty string there is nothing to normalize. It signals the caller passed an empty/whitespace value or coerced a missing value to an empty string.

Source

Thrown at clis/hltv/utils.js:462

export function parseHltvDate(value) {
  const raw = String(value ?? '').trim();
  const shortMatch = raw.match(/^(\d{2})\/(\d{2})\/(\d{2})$/);
  if (shortMatch) {
    const [, dd, mm, yy] = shortMatch;
    return `20${yy}-${mm}-${dd}`;
  }
  const longMatch = raw.match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
  if (longMatch) {
    const [, dd, mm, yyyy] = longMatch;
    return `${yyyy}-${mm}-${dd}`;
  }
  return raw;
}

export function normalizeMatchUrl(value) {
  const raw = String(value ?? '').trim();
  if (!raw) throw new ArgumentError('match is required');
  const url = /^https?:\/\//i.test(raw) ? parseHltvUserUrl(raw, 'match') : new URL(raw.replace(/^\/+/, ''), `${BASE}/`);
  if (!/^\/(?:matches\/\d+\/|stats\/matches\/(?:mapstatsid\/)?\d+\/)/.test(url.pathname)) {
    throw new ArgumentError('match must be an HLTV match, stats series, or mapstats URL');
  }
  return url;
}

function buildPerformanceUrl(mapstatsUrl) {
  const url = new URL(mapstatsUrl, BASE);
  url.pathname = url.pathname.replace('/stats/matches/mapstatsid/', '/stats/matches/performance/mapstatsid/');
  return url;
}

export async function resolveMatchMapUrls(page, match) {
  const url = normalizeMatchUrl(match);
  if (/^\/stats\/matches\/mapstatsid\/\d+\//.test(url.pathname)) return [url.toString()];

  await gotoAndWait(page, url, 'a[href*="/stats/matches/mapstatsid/"]', 'hltv match map link page');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a valid match reference, e.g. 'https://www.hltv.org/matches/2380210/...' or a stats mapstats URL.
  2. Guard before calling: skip or substitute when the value is missing — if (matchValue?.trim()) normalizeMatchUrl(matchValue).
  3. Fix the upstream source so missing matches yield null/undefined (skip) instead of '' (throw).

Example fix

// before
normalizeMatchUrl(config.matchUrl ?? ''); // throws when unset
// after
if (config.matchUrl?.trim()) {
  normalizeMatchUrl(config.matchUrl);
} else {
  // skip match or use a fallback
}
Defensive patterns

Strategy: validation

Validate before calling

function hasMatchUrl(v) {
  return typeof v === 'string' && v.trim().length > 0;
}
if (!hasMatchUrl(input)) throw new TypeError('match URL is required');

Type guard

function isMatchInput(v) {
  return typeof v === 'string' && v.trim() !== '';
}

Try / catch

try {
  const url = normalizeMatchUrl(input);
} catch (err) {
  if (err.name === 'ArgumentError' && err.message === 'match is required') {
    return null; // no match supplied — skip rather than crash
  }
  throw err;
}

Prevention

When it happens

Trigger: normalizeMatchUrl(''), normalizeMatchUrl(null) (explicit null with no default), normalizeMatchUrl(' '), or String() coercion of an empty value (e.g. an empty array []) reaching the function via match-lookup helpers.

Common situations: Env vars/CLI args like MATCH_URL='' overriding undefined; scraping pipelines where an earlier regex produced '' for a missing match link; config files with empty match fields.

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/3b1703ece7b93ce0. Report an issue: GitHub.