jackwener/OpenCLI · error · CommandExecutionError

github-trending parser drift: missing ${field} for ${repo}

Error message

github-trending parser drift: missing ${field} for ${repo}

What it means

During HTML parsing of the GitHub Trending page, a repository row was matched but a required count field (stars, forks, or stars-since) could not be parsed, so assertCount throws this CommandExecutionError. The library treats an unparsable count as 'parser drift' — GitHub changed its markup and the scraper's regexes no longer align with the page structure.

Source

Thrown at clis/github-trending/repos.js:40

function stripTags(value) {
    return String(value ?? '').replace(/<[^>]*>/g, '');
}

function parseCount(value) {
    if (value == null) return null;
    const digits = String(value).replace(/[,\s]/g, '');
    if (!/^\d+$/.test(digits)) return null;
    return Number(digits);
}

function escapeRegExp(value) {
    return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

function assertCount(value, field, repo) {
    const count = parseCount(value);
    if (count == null) {
        throw new CommandExecutionError(`github-trending parser drift: missing ${field} for ${repo}`);
    }
    return count;
}

function hasExplicitEmptyTrending(html) {
    return /don.t have any trending repositories/i.test(stripTags(html))
        || /no trending repositories/i.test(stripTags(html));
}

function parseTrendingHtml(html, limit) {
    const blocks = Array.from(String(html ?? '').matchAll(/<article\b[^>]*class="[^"]*\bBox-row\b[^"]*"[^>]*>([\s\S]*?)<\/article>/g))
        .map((match) => match[1]);
    const rows = [];

    if (blocks.length === 0) {
        if (hasExplicitEmptyTrending(html)) return rows;
        throw new CommandExecutionError('github-trending parser drift: no repository rows found');
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Update the CLI/scraper package to the latest version where the parser regexes may already be fixed
  2. Retry later if GitHub is mid-deploy of a UI change; check whether the trending page renders normally in a browser
  3. Patch parseCount/assertCount regexes locally to accommodate the new markup and file an issue upstream

Example fix

// before
const count = parseCount(value);
// after: tolerate abbreviated counts
const count = parseCount(value) ?? parseAbbreviatedCount(value); // '1.2k' -> 1200
Defensive patterns

Strategy: fallback

Validate before calling

null

Type guard

function isParserDrift(e) { return e instanceof Error && /parser drift/.test(e.message); }

Try / catch

try {
  const repos = parseTrendingHtml(html);
} catch (e) {
  if (/parser drift/.test(e.message)) { reportParserDrift(e); return cachedOrEmptyResult(); }
  throw e;
}

Prevention

When it happens

Trigger: parseTrendingHtml processes a Box-row article block whose stars/forks/starsSince text does not match the parseCount format (e.g. GitHub changes '1,234 stars' markup to a different label, icon-only counts, or localized number formats).

Common situations: GitHub ships a redesign of the Trending page; scraping a localized-language page where 'stars'/'forks' labels differ; page served with new count formatting like 'k' abbreviations the parser doesn't handle.

Related errors


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