jackwener/OpenCLI · error · CommandExecutionError
wikipedia page request failed: ${error?.message || error}
Error message
wikipedia page request failed: ${error?.message || error} What it means
fetch() throws on network-level failures (DNS, TCP, TLS, aborts), and page.js wraps that in a CommandExecutionError prefixed 'wikipedia page request failed:'. This fires before any HTTP status is examined — the request never completed.
Source
Thrown at clis/wikipedia/page.js:60
url.searchParams.set('action', 'query');
url.searchParams.set('format', 'json');
url.searchParams.set('formatversion', '2');
url.searchParams.set('prop', 'extracts|info|description');
url.searchParams.set('inprop', 'url');
url.searchParams.set('explaintext', '1');
url.searchParams.set('redirects', '1');
url.searchParams.set('titles', title);
let resp;
try {
resp = await fetch(url, {
headers: {
'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',
'Accept': 'application/json',
},
});
} catch (error) {
throw new CommandExecutionError(`wikipedia page request failed: ${error?.message || error}`);
}
if (!resp.ok) {
throw new CommandExecutionError(`wikipedia page failed: HTTP ${resp.status}`);
}
let data;
try {
data = await resp.json();
} catch (error) {
throw new CommandExecutionError(`wikipedia returned malformed JSON: ${error?.message || error}`);
}
if (data?.error) {
throw new CommandExecutionError(`wikipedia API error: ${data.error.info || data.error.code}`);
}
const pages = Array.isArray(data?.query?.pages) ? data.query.pages : [];
const page = pages[0];
if (!page || page.missing) {
throw new EmptyResultError('wikipedia page', `No article "${title}" on ${lang}.wikipedia.org. Try \`opencli wikipedia search\` first.`);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Check network connectivity and DNS resolution of en.wikipedia.org
- Fix the lang value so the hostname is a real Wikipedia subdomain
- Verify proxy/firewall allows HTTPS to wikipedia.org and set HTTPS_PROXY if needed
- Upgrade to Node 18+ (or a runtime with global fetch) if fetch is undefined
Example fix
// before await run(['wikipedia', 'page', title, '--lang', 'english']); // bad hostname, DNS fails // after await run(['wikipedia', 'page', title, '--lang', 'en']);
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight reachability check
const online = await fetch('https://en.wikipedia.org/w/api.php?action=query&format=json', { method: 'HEAD' }).then(r => r.ok).catch(() => false);
if (!online) throw new Error('wikipedia.org unreachable from this network'); Try / catch
try {
return await pageCommand(args);
} catch (err) {
if (err instanceof CommandExecutionError && err.message.includes('request failed')) {
console.error('network problem reaching wikipedia.org — check connectivity/proxy/DNS');
return null;
}
throw err;
} Prevention
- Check connectivity/DNS before batch runs
- Use a valid lang code so the subdomain exists
- Configure HTTPS_PROXY for corporate networks
- Run on Node 18+ (or another runtime with global fetch)
When it happens
Trigger: No internet connection or DNS failure resolving <lang>.wikipedia.org; TLS interception/firewall blocking the request; a typo'd lang creating an invalid hostname that fails DNS; Node < 18 where global fetch is undefined (TypeError caught here).
Common situations: Offline development or CI without network egress; corporate proxies rejecting the request; using an invalid lang that produces a nonexistent subdomain; running on an old runtime without fetch.
Related errors
- archive wayback request failed: ${error?.message || error}
- Failed to fetch Chess.com API ${url}: ${error?.message || er
- coingecko exchanges request failed: ${err?.message ?? err}
- coingecko global request failed: ${err?.message ?? err}
- coingecko top request failed: ${error?.message || error}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b44d780a54671bb3.
Report an issue: GitHub.