jackwener/OpenCLI · error · ArgumentError

event query parameter must be a numeric event id

Error message

event query parameter must be a numeric event id

What it means

parseEventRef accepts a numeric event id, an /events/:id URL, or a stats URL carrying ?event=. When a stats URL's event query parameter is present but not purely numeric, it throws this ArgumentError instead of accepting a malformed id.

Source

Thrown at clis/hltv/utils.js:147

    matchStats: /^\/stats\/matches\/mapstatsid\/(\d+)\//,
    statsSeries: /^\/stats\/matches\/(\d+)\//,
    match: /^\/matches\/(\d+)\//,
  };
  const match = path.match(patterns[kind]);
  return match ? match[1] : null;
}

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);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the plain numeric event id (e.g. 7148) instead of a URL
  2. Use a full canonical stats URL with a numeric event= value copied from the browser address bar
  3. Verify the URL was not truncated or altered when copying

Example fix

// before
--event "https://www.hltv.org/stats?event=abc"
// after
--event 7148
Defensive patterns

Strategy: validation

Validate before calling

const m = /^[?&]event=(\d+)$/.exec(eventRef.split('?')[1] ? '?' + eventRef.split('?')[1] : '') || null;
const isValidEventRef = /^\d+$/.test(eventRef) || /\/events\/\d+\//.test(eventRef) || m !== null;

Type guard

const isNumericEventQuery = (u) => { try { return /^\d+$/.test(new URL(u).searchParams.get('event') ?? ''); } catch { return false; } };

Try / catch

try {
  await hltv.eventStats({ event: ref });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('numeric event id')) {
    console.error('Extract the digits from event= in your URL and pass them alone');
  } else throw e;
}

Prevention

When it happens

Trigger: Passing a URL like https://www.hltv.org/stats?event=abc or with a truncated/non-numeric event query value; hand-editing a copied URL and mangling the id.

Common situations: Truncated paste of a long stats URL; URL-encoding artifacts breaking the digits; constructing URLs programmatically with an undefined variable interpolated into event=.

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/05ddb5f823bbe6be. Report an issue: GitHub.