jackwener/OpenCLI · error · ArgumentError

event must be an event id, an /events/:id URL, a stats URL w

Error message

event must be an event id, an /events/:id URL, a stats URL with event=, or all

What it means

parseEventRef throws this when the input matches none of the supported event reference formats: a bare numeric id, an /events/:id/... URL, or a stats URL with a numeric event= query parameter. The message enumerates every accepted shape.

Source

Thrown at clis/hltv/utils.js:154

export function parseEventRef(value) {
  const raw = String(value ?? '').trim();
  if (!raw || raw === 'all') return null;
  if (/^\d+$/.test(raw)) return raw;

  let url = null;
  if (/^https?:\/\//i.test(raw)) url = parseHltvUserUrl(raw, 'event');
  if (url?.searchParams.get('event')) {
    const eventId = url.searchParams.get('event');
    if (/^\d+$/.test(eventId)) return eventId;
    throw new ArgumentError('event query parameter must be a numeric event id');
  }

  const path = (url ? url.pathname : raw).replace(/^\/+/, '');
  const eventPath = path.match(/^events\/(\d+)\//i);
  if (eventPath) return eventPath[1];

  throw new ArgumentError('event must be an event id, an /events/:id URL, a stats URL with event=, or all');
}

export function parseTeamRef(value, defaultValue = null) {
  const raw = String(value ?? defaultValue ?? '').trim();
  if (!raw) throw new ArgumentError('team is required');

  let path = raw;
  if (/^https?:\/\//i.test(raw)) path = parseHltvUserUrl(raw, 'team').pathname;
  path = path.replace(/^https?:\/\/[^/]+/i, '').replace(/^\/+/, '');

  const statsMatch = path.match(/^stats\/teams(?:\/matches)?\/(\d+)\/([a-z0-9-]+)/i);
  const teamMatch = path.match(/^team\/(\d+)\/([a-z0-9-]+)/i);
  const compactMatch = path.match(/^(\d+)\/([a-z0-9-]+)$/i);
  const match = statsMatch || teamMatch || compactMatch;
  if (!match) {
    throw new ArgumentError('team must be like 6667/falcons, a team URL, or a stats team URL');
  }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert the input to the numeric event id found in the event page URL (/events/7148/iem-katowice-2024)
  2. Use the exact event URL copied from the HLTV event page
  3. Or use the stats URL containing ?event=<numeric id>
  4. Use 'all' if the command supports it and you want to omit the event filter

Example fix

// before
--event iem-katowice-2024
// after
--event 7148
Defensive patterns

Strategy: validation

Validate before calling

const isValidEventRef = (v) => /^\d+$/.test(String(v)) || /^https?:\/\/(www\.)?hltv\.org\/events\/\d+\//i.test(String(v)) || /^https?:\/\/[^?]*\??.*event=\d+/.test(String(v)) || v === 'all';

Type guard

const isEventRef = (v) => ['string','number'].includes(typeof v) && isValidEventRef(String(v));

Try / catch

try {
  await hltv.matches({ event: ref });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('event must be an event id')) {
    console.error('Use a numeric id, /events/:id URL, stats URL with event=, or "all"');
  } else throw e;
}

Prevention

When it happens

Trigger: Passing an event slug/name like 'iem-katowice-2024', a non-HLTV URL, a /events/:id URL missing the numeric id, or an empty/garbage string.

Common situations: Users typing event names instead of ids; copying results-page URLs that are not /events/:id; old scripts using a URL format the parser never supported.

Related errors


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