{"record":{"id":"05ddb5f823bbe6be","repo":"jackwener/OpenCLI","slug":"event-query-parameter-must-be-a-numeric-event-id","errorCode":null,"errorMessage":"event query parameter must be a numeric event id","messagePattern":"event query parameter must be a numeric event id","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hltv/utils.js","lineNumber":147,"sourceCode":"    matchStats: /^\\/stats\\/matches\\/mapstatsid\\/(\\d+)\\//,\n    statsSeries: /^\\/stats\\/matches\\/(\\d+)\\//,\n    match: /^\\/matches\\/(\\d+)\\//,\n  };\n  const match = path.match(patterns[kind]);\n  return match ? match[1] : null;\n}\n\nexport function parseEventRef(value) {\n  const raw = String(value ?? '').trim();\n  if (!raw || raw === 'all') return null;\n  if (/^\\d+$/.test(raw)) return raw;\n\n  let url = null;\n  if (/^https?:\\/\\//i.test(raw)) url = parseHltvUserUrl(raw, 'event');\n  if (url?.searchParams.get('event')) {\n    const eventId = url.searchParams.get('event');\n    if (/^\\d+$/.test(eventId)) return eventId;\n    throw new ArgumentError('event query parameter must be a numeric event id');\n  }\n\n  const path = (url ? url.pathname : raw).replace(/^\\/+/, '');\n  const eventPath = path.match(/^events\\/(\\d+)\\//i);\n  if (eventPath) return eventPath[1];\n\n  throw new ArgumentError('event must be an event id, an /events/:id URL, a stats URL with event=, or all');\n}\n\nexport function parseTeamRef(value, defaultValue = null) {\n  const raw = String(value ?? defaultValue ?? '').trim();\n  if (!raw) throw new ArgumentError('team is required');\n\n  let path = raw;\n  if (/^https?:\\/\\//i.test(raw)) path = parseHltvUserUrl(raw, 'team').pathname;\n  path = path.replace(/^https?:\\/\\/[^/]+/i, '').replace(/^\\/+/, '');\n\n  const statsMatch = path.match(/^stats\\/teams(?:\\/matches)?\\/(\\d+)\\/([a-z0-9-]+)/i);","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hltv/utils.js#L129-L165","documentation":"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.","triggerScenarios":"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.","commonSituations":"Truncated paste of a long stats URL; URL-encoding artifacts breaking the digits; constructing URLs programmatically with an undefined variable interpolated into event=.","solutions":["Use the plain numeric event id (e.g. 7148) instead of a URL","Use a full canonical stats URL with a numeric event= value copied from the browser address bar","Verify the URL was not truncated or altered when copying"],"exampleFix":"// before\n--event \"https://www.hltv.org/stats?event=abc\"\n// after\n--event 7148","handlingStrategy":"validation","validationCode":"const m = /^[?&]event=(\\d+)$/.exec(eventRef.split('?')[1] ? '?' + eventRef.split('?')[1] : '') || null;\nconst isValidEventRef = /^\\d+$/.test(eventRef) || /\\/events\\/\\d+\\//.test(eventRef) || m !== null;","typeGuard":"const isNumericEventQuery = (u) => { try { return /^\\d+$/.test(new URL(u).searchParams.get('event') ?? ''); } catch { return false; } };","tryCatchPattern":"try {\n  await hltv.eventStats({ event: ref });\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message.includes('numeric event id')) {\n    console.error('Extract the digits from event= in your URL and pass them alone');\n  } else throw e;\n}","preventionTips":["Copy stats URLs straight from the browser without hand-editing","Prefer passing the bare numeric id over URLs","Sanitize programmatic URL construction: only interpolate validated numeric ids"],"tags":["cli","validation","url-parsing","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}