{"record":{"id":"606a4698240e5da4","repo":"jackwener/OpenCLI","slug":"label-must-be-a-valid-hltv-org-url","errorCode":null,"errorMessage":"${label} must be a valid hltv.org URL","messagePattern":"(.+?) must be a valid hltv\\.org URL","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hltv/utils.js","lineNumber":14,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError, TimeoutError } from '@jackwener/opencli/errors';\n\nexport const BASE = 'https://www.hltv.org';\n\nfunction isHltvHost(hostname) {\n  return hostname === 'hltv.org' || hostname === 'www.hltv.org';\n}\n\nfunction parseHltvUserUrl(raw, label) {\n  let url;\n  try {\n    url = new URL(raw);\n  } catch {\n    throw new ArgumentError(`${label} must be a valid hltv.org URL`);\n  }\n  if (!isHltvHost(url.hostname)) {\n    throw new ArgumentError(`${label} must be an hltv.org URL`);\n  }\n  return url;\n}\n\nexport const EVENT_TYPES = {\n  all: null,\n  majors: 'Majors',\n  bigEvents: 'BigEvents',\n  mvpEvents: 'MvpEvents',\n  lan: 'Lan',\n  online: 'Online',\n};\n\nexport const RANKING_FILTERS = {\n  all: null,","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hltv/utils.js#L1-L32","documentation":"parseHltvUserUrl validates that a user-supplied raw string is a parseable URL before further ref parsing. If new URL(raw) throws (malformed URL), it raises this ArgumentError including the parameter label. It is the first of two URL checks (the second checks the hostname).","triggerScenarios":"Passing a bare domain like 'hltv.org/team/123' without scheme, a typo'd URL, an empty string, or any non-URL string to parseEventRef/parseTeamRef/parsePlayerRef or url helpers.","commonSituations":"Users pasting 'www.hltv.org/...' without https://; config files storing team refs as paths not full URLs; shell quoting stripping characters; concatenation bugs building the URL string.","solutions":["Prefix the input with https:// if the scheme is missing","Validate the string with new URL() before passing it to the library","Ensure full absolute URLs like https://www.hltv.org/team/123/name are used","Catch ArgumentError and show a clear message naming the offending parameter"],"exampleFix":"// before\nconst ref = parseTeamRef('hltv.org/team/4608/natus-vincere'); // throws\n// after\nconst raw = 'hltv.org/team/4608/natus-vincere';\nconst ref = parseTeamRef(raw.startsWith('http') ? raw : `https://${raw}`);","handlingStrategy":"validation","validationCode":"function toAbsoluteHltvUrl(raw) {\n  const s = /^https?:\\/\\//i.test(raw) ? raw : `https://${raw}`;\n  return new URL(s); // throws TypeError early if still malformed\n}\n// then: parseTeamRef(toAbsoluteHltvUrl(input).href);","typeGuard":"function isParseableUrl(raw) { try { new URL(raw); return true; } catch { return false; } }","tryCatchPattern":"try {\n  const ref = parseTeamRef(raw);\n} catch (err) {\n  if (err instanceof ArgumentError && /must be a valid hltv\\.org URL/.test(err.message)) {\n    return fail(`malformed URL for team argument: ${raw}`);\n  }\n  throw err;\n}","preventionTips":["Store full absolute https:// URLs in configs, never bare paths","Sanitize user paste: trim and prepend https:// when the scheme is missing","Run new URL() on inputs at the boundary before calling library parsers","Watch shell quoting that can mangle URL characters"],"tags":["argument-error","validation","url"],"backgroundTag":"invalid-url-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}