jackwener/OpenCLI · error · CommandExecutionError
Network failure fetching ${label}: ${detail}
Error message
Network failure fetching ${label}: ${detail} What it means
fetchJson in clis/stackoverflow/read.js wraps the initial fetch() call in try/catch and rethrows a CommandExecutionError when the request itself fails (DNS, TLS, connection refused, timeout), labeling the failing resource and including the underlying error message. It is thrown before any HTTP status is inspected, so the Stack Exchange API was never reached successfully.
Source
Thrown at clis/stackoverflow/read.js:35
* - first row is the question itself (`type=POST`)
* - one row per top-level question comment (`type=Q-COMMENT`)
* - per answer: an `ANSWER` row plus its `A-COMMENT` rows indented under it
* - the accepted answer (if any) is surfaced first and tagged `accepted=true`
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
const SE_API_BASE = 'https://api.stackexchange.com/2.3';
const SE_SITE = 'stackoverflow';
const SE_MAX_PAGE_SIZE = 100;
async function fetchJson(url, label) {
let res;
try {
res = await fetch(url);
} catch (e) {
const detail = e instanceof Error ? e.message : String(e);
throw new CommandExecutionError(
`Network failure fetching ${label}: ${detail}`,
'Check connectivity to api.stackexchange.com',
);
}
if (res.status === 404) {
throw new EmptyResultError(label, `${label} not found`);
}
if (!res.ok) {
throw new CommandExecutionError(
`Stack Exchange API HTTP ${res.status} for ${label}`,
'Check the question id and quota (300/day per IP)',
);
}
let json;
try {
json = await res.json();
} catch (e) {
const detail = e instanceof Error ? e.message : String(e);View on GitHub (pinned to 49907e53dc)
Solutions
- Verify general connectivity: curl -I https://api.stackexchange.com/2.2/site/stackoverflow
- Check DNS resolution of api.stackexchange.com (nslookup/dig); fix resolver or /etc/hosts if it fails
- If behind a proxy, set HTTP_PROXY/HTTPS_PROXY (and NODE_USE_ENV_PROXY or an agent) so Node's fetch routes through it
- Retry after a short backoff for transient outages; the error suggests 'Check connectivity to api.stackexchange.com'
- Disable TLS-intercepting VPN/firewall temporarily to confirm it is the cause
Example fix
async function fetchWithRetry(url, retries = 3) {
for (let i = 0; i < retries; i++) {
try {
return await fetch(url);
} catch (e) {
if (i === retries - 1) throw e;
await new Promise(r => setTimeout(r, 1000 * 2 ** i));
}
}
} Defensive patterns
Strategy: retry
Validate before calling
async function canReachStackExchange() {
try {
const res = await fetch('https://api.stackexchange.com/2.2/info?site=stackoverflow');
return res.ok;
} catch {
return false;
}
}
// check before batch calls: if (!(await canReachStackExchange())) abort; Try / catch
async function withNetworkRetry(fn, retries = 3) {
for (let i = 0; ; i++) {
try {
return await fn();
} catch (e) {
const isNetwork = /Network failure fetching/.test(e?.message ?? '');
if (!isNetwork || i >= retries) throw e;
await new Promise(r => setTimeout(r, 1000 * 2 ** i));
}
}
}
const data = await withNetworkRetry(() => qData(id)); Prevention
- Set HTTPS_PROXY/HTTP_PROXY when behind a corporate proxy so Node's fetch routes correctly
- Check DNS for api.stackexchange.com in containers/CI before running batch scripts
- Use exponential backoff on fetch failures instead of failing the whole batch
- Verify VPN/captive-portal connectivity before long-running API scripts
When it happens
Trigger: Calling any of fetchJson's callers (qData, answersData, acceptedData, qCommentsData, ansCommentsData) against api.stackexchange.com while fetch() rejects: offline network, DNS failure for api.stackexchange.com, firewall/proxy blocking the request, TLS interception, or the process being killed mid-request.
Common situations: Working behind a corporate proxy that Node's fetch doesn't honor; VPN drop or captive portal; DNS resolver misconfiguration in containers; ISP or corporate firewall blocking api.stackexchange.com; transient internet outage during a script run.
Related errors
- `${label} request failed: ${err?.message ?? err}`
- ${label} request failed: ${err?.message ?? err}
- FETCH_ERROR
- ${label} request failed: ${err?.message ?? err}
- Failed to fetch WeRead search page: ${error instanceof Error
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5724a52b1759c0af.
Report an issue: GitHub.