jackwener/OpenCLI · error · ArgumentError

${label} must be a valid hltv.org URL

Error message

${label} must be a valid hltv.org URL

What it means

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

Source

Thrown at clis/hltv/utils.js:14

import { ArgumentError, CommandExecutionError, EmptyResultError, TimeoutError } from '@jackwener/opencli/errors';

export const BASE = 'https://www.hltv.org';

function isHltvHost(hostname) {
  return hostname === 'hltv.org' || hostname === 'www.hltv.org';
}

function parseHltvUserUrl(raw, label) {
  let url;
  try {
    url = new URL(raw);
  } catch {
    throw new ArgumentError(`${label} must be a valid hltv.org URL`);
  }
  if (!isHltvHost(url.hostname)) {
    throw new ArgumentError(`${label} must be an hltv.org URL`);
  }
  return url;
}

export const EVENT_TYPES = {
  all: null,
  majors: 'Majors',
  bigEvents: 'BigEvents',
  mvpEvents: 'MvpEvents',
  lan: 'Lan',
  online: 'Online',
};

export const RANKING_FILTERS = {
  all: null,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Prefix the input with https:// if the scheme is missing
  2. Validate the string with new URL() before passing it to the library
  3. Ensure full absolute URLs like https://www.hltv.org/team/123/name are used
  4. Catch ArgumentError and show a clear message naming the offending parameter

Example fix

// before
const ref = parseTeamRef('hltv.org/team/4608/natus-vincere'); // throws
// after
const raw = 'hltv.org/team/4608/natus-vincere';
const ref = parseTeamRef(raw.startsWith('http') ? raw : `https://${raw}`);
Defensive patterns

Strategy: validation

Validate before calling

function toAbsoluteHltvUrl(raw) {
  const s = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
  return new URL(s); // throws TypeError early if still malformed
}
// then: parseTeamRef(toAbsoluteHltvUrl(input).href);

Type guard

function isParseableUrl(raw) { try { new URL(raw); return true; } catch { return false; } }

Try / catch

try {
  const ref = parseTeamRef(raw);
} catch (err) {
  if (err instanceof ArgumentError && /must be a valid hltv\.org URL/.test(err.message)) {
    return fail(`malformed URL for team argument: ${raw}`);
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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