jackwener/OpenCLI · error · CommandExecutionError
github-trending request failed: HTTP ${resp.status}
Error message
github-trending request failed: HTTP ${resp.status} What it means
github-trending scrapes the GitHub trending HTML page via fetch and throws this CommandExecutionError when the HTTP response is not ok (e.g. 403, 404, 5xx). It is thrown after the fetch resolves successfully but the response status indicates failure, distinct from network-level fetch exceptions which produce the error?.message variant.
Source
Thrown at clis/github-trending/repos.js:146
const language = String(args.language ?? '').trim();
const path = language ? `/trending/${encodeURIComponent(language)}` : '/trending';
const url = new URL(`https://github.com${path}`);
url.searchParams.set('since', since);
let resp;
try {
resp = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; opencli/github-trending)',
Accept: 'text/html',
},
});
} catch (error) {
throw new CommandExecutionError(`github-trending request failed: ${error?.message || error}`);
}
if (!resp.ok) {
throw new CommandExecutionError(`github-trending request failed: HTTP ${resp.status}`);
}
const html = await resp.text();
const rows = parseTrendingHtml(html, limit);
if (rows.length === 0) {
throw new EmptyResultError('github-trending', language
? `no trending repositories for language "${language}" (${since})`
: `no trending repositories (${since})`);
}
return rows.map((row, index) => ({
rank: index + 1,
repo: row.repo,
description: row.description,
language: row.language,
stars: row.stars,
forks: row.forks,
starsSince: row.starsSince,View on GitHub (pinned to 49907e53dc)
Solutions
- Check resp.status in a browser/curl for the same trending URL to identify 403 vs 404 vs 5xx
- If 403: slow down request frequency, add/rotate appropriate User-Agent headers, or run from a residential IP
- If 404: fix the language argument to a valid GitHub trending language slug (e.g. 'javascript', not 'JavaScript' with spaces)
- If 5xx: retry later; check GitHub status page
- Wrap the call in try/catch and fall back to a cached or alternate trending source
Example fix
// before
const rows = await runGithubTrending({ language: 'C++' });
// after
try {
const rows = await runGithubTrending({ language: 'cpp' });
} catch (e) {
if (String(e.message).includes('HTTP 403')) {
await sleep(60_000); // back off on rate limiting
}
const rows = await getCachedTrending();
} Defensive patterns
Strategy: try-catch
Validate before calling
const resp = await fetch(trendingUrl);
if (!resp.ok) {
throw new Error(`upstream trending HTTP ${resp.status} — fix URL/backoff before calling CLI`);
} Type guard
function isOkResponse(resp) {
return typeof resp === 'object' && resp !== null && resp.ok === true;
} Try / catch
try {
const rows = await runGithubTrending({ language, since });
} catch (e) {
const m = /HTTP (\d{3})/.exec(String(e.message));
if (m && m[1] === '403') scheduleBackoffAndRetry();
else fallbackToCache();
} Prevention
- Rate-limit trending scrapes and add jitter/backoff
- Validate language slugs against known GitHub trending language list
- Set a realistic User-Agent to reduce bot-detection 403s
- Monitor GitHub status before running scrapes in CI
- Cache last successful results as a fallback
When it happens
Trigger: fetch to https://github.com/trending resolves with resp.ok === false — e.g. GitHub returns 403 (rate limit / bot detection), 404 (bad language slug in the URL), or 5xx (GitHub outage).
Common situations: Scraping too frequently and hitting GitHub rate limits or abuse detection; passing an invalid language filter that produces a 404 URL; GitHub HTML endpoint temporarily down or blocked from CI/datacenter IPs; corporate proxy returning an error page.
Related errors
- 1point3acres request failed: HTTP ${res.status} ${res.status
- Barchart greeks request failed: HTTP ${data.status}${data.st
- HTTP ${code}
- Sina blog search failed: HTTP ${resp.status}
- Request failed: ${result?.status} ${result?.statusText} (${r
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/937510a16b4d234a.
Report an issue: GitHub.