jackwener/OpenCLI · error · CommandExecutionError

HLTV parser returned a malformed URL

Error message

HLTV parser returned a malformed URL

What it means

absolutizeUrl resolves URLs extracted from parsed HLTV HTML against the HLTV base URL. If new URL() fails — meaning the parser produced something that is not a usable URL or path — it throws CommandExecutionError('HLTV parser returned a malformed URL'). This usually indicates the site's markup changed and the scraper captured a bad href, or an internal bug fed an invalid string.

Source

Thrown at clis/hltv/utils.js:106

  const raw = String(value ?? '').replace(/\s+/g, ' ').trim();
  if (!raw || raw === '-' || raw.toLowerCase() === 'n/a') return null;
  const match = raw.replace(/,/g, '').match(/-?\d+(?:\.\d+)?/);
  if (!match) return null;
  const n = Number(match[0]);
  return Number.isFinite(n) ? n : null;
}

export function parseMoneyUsd(value) {
  return parseNumber(String(value ?? '').replace(/\$/g, ''));
}

export function absolutizeUrl(value) {
  if (!value) return null;
  let url;
  try {
    url = new URL(value, BASE);
  } catch {
    throw new CommandExecutionError('HLTV parser returned a malformed URL');
  }
  if (!isHltvHost(url.hostname)) {
    throw new CommandExecutionError(`HLTV parser returned an off-domain URL: ${url.toString()}`);
  }
  return url.toString();
}

export function extractIdFromUrl(url, kind) {
  if (!url) return null;
  let parsed;
  try {
    parsed = new URL(url, BASE);
  } catch {
    return null;
  }
  if (!isHltvHost(parsed.hostname)) return null;
  const path = parsed.pathname;
  const patterns = {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Update the CLI/library to the latest version (selectors may have been fixed for the new markup)
  2. Inspect the page at the failing command's endpoint to confirm the link structure changed
  3. Report the failing command and URL to the project so the parser can be patched
  4. If you control the input, pass canonical /matches/... style paths or full https URLs
Defensive patterns

Strategy: try-catch

Validate before calling

function looksLikePath(u) { return typeof u === 'string' && u.length > 0 && !/[\s<>"']/.test(u) && /^([a-z]+:\/\/)?[\w./?#&=-]+$/i.test(u); }
if (result.url && !looksLikePath(result.url)) throw new Error('parser produced malformed URL');

Type guard

const isResolvableUrl = (v) => { try { new URL(v, 'https://www.hltv.org'); return true; } catch { return false; } };

Try / catch

try {
  await hltv.match(id);
} catch (e) {
  if (e.name === 'CommandExecutionError' && e.message.includes('malformed URL')) {
    console.error('Parser output unusable — update the CLI or report the page');
  } else throw e;
}

Prevention

When it happens

Trigger: A parsed anchor href is empty-but-truthy garbage, contains invalid characters, or the HTML structure changed so the extractor grabs the wrong attribute content.

Common situations: HLTV redesigns a page and selectors start picking up malformed hrefs; caching/proxy layers injecting text into links; running an outdated CLI against an updated site.

Understand the failure class

Related errors


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