jackwener/OpenCLI · error · CommandExecutionError

hltv team-map-pool parser returned an unexpected shape

Error message

hltv team-map-pool parser returned an unexpected shape

What it means

The team-map-pool command runs an in-page parser and expects it to return an array of rows. If the page evaluation returns anything other than an array (null, undefined, object), a CommandExecutionError is thrown because the parser contract was violated — usually meaning HLTV's page structure changed. Distinct from the empty-rows error that follows it.

Source

Thrown at clis/hltv/team-map-pool.js:91

        byMap.set(mapName, {
          category: 'map',
          key: mapName,
          teamId: payload.teamId,
          team,
          record,
          winRate,
          totalRounds,
          firstKillWinPct,
          firstDeathWinPct,
          pickPct,
          banPct,
          mapUrl: byMap.get(mapName)?.mapUrl ?? null,
        });
      }
      return [...byMap.values()];
    }, { base: BASE, teamId, slug });

    if (!Array.isArray(rawRows)) throw new CommandExecutionError('hltv team-map-pool parser returned an unexpected shape');
    if (rawRows.length === 0) throw new EmptyResultError('hltv team-map-pool', `No map-pool rows found for team ${teamId}/${slug}`);

    const rows = rawRows.map((row) => {
      const record = splitRecord(row.record);
      const maps = record.wins === null ? null : (record.wins ?? 0) + (record.draws ?? 0) + (record.losses ?? 0);
      return {
        category: row.category,
        key: row.key,
        teamId: row.teamId,
        team: row.team,
        maps,
        winMaps: record.wins,
        lossMaps: record.losses,
        winRatePct: parseNumber(row.winRate),
        avgRoundDiff: null,
        details: {
          draws: record.draws,
          totalRounds: parseNumber(row.totalRounds),

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Update the library to a version matching current HLTV markup
  2. Log/dump the raw evaluate result to see what shape actually came back
  3. Retry later in case of a transient page/CDN issue
  4. Add a fallback that inspects the page HTML for markup changes

Example fix

// before
const rawRows = await page.evaluate(parser, opts);
if (!Array.isArray(rawRows)) throw new CommandExecutionError('unexpected shape');
// after
const rawRows = await page.evaluate(parser, opts);
if (!Array.isArray(rawRows)) {
  console.error('parser returned:', typeof rawRows, rawRows); // diagnose markup change
  throw new CommandExecutionError('hltv team-map-pool parser returned an unexpected shape');
}
Defensive patterns

Strategy: retry

Validate before calling

// pre-check the page actually rendered the map-pool section
await page.waitForSelector('div.stats-rows, .map-pool', { timeout: 15000 }).catch(() => null);

Type guard

function isArrayRows(v) { return Array.isArray(v) && v.every((r) => r && typeof r === 'object'); }

Try / catch

try {
  await teamMapPool(page, { teamId, slug });
} catch (err) {
  if (err instanceof CommandExecutionError && /unexpected shape/.test(err.message)) {
    await sleep(5000); // transient page issue; also suspect HLTV markup change
    return retryOnce();
  }
  throw err;
}

Prevention

When it happens

Trigger: HLTV changed the team map-pool page markup so the page.evaluate returns undefined/null; page failed to render the expected widget and the parser returns a non-array; site serves an error/consent page instead of the data.

Common situations: HLTV frontend redesign breaking selectors; anti-bot or consent interstitial replacing content; network returning an error page parsed as non-array; library out of sync with current site markup.

Related errors


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