jackwener/OpenCLI · error · CommandExecutionError
wikipedia API error: ${data.error.info || data.error.code}
Error message
wikipedia API error: ${data.error.info || data.error.code} What it means
The opencli wikipedia page command throws CommandExecutionError when the MediaWiki API responds with JSON containing an `error` object (e.g. invalidpage, badparams, rate-limited). The message surfaces the API's `info` description, falling back to the error `code`. It means the request reached Wikipedia but the API refused it rather than returning query results.
Source
Thrown at clis/wikipedia/page.js:72
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.`);
}
const fullExtract = String(page.extract ?? '');
if (!fullExtract.trim()) {
throw new EmptyResultError('wikipedia page', `Article "${page.title}" exists but has no plain-text extract (likely a disambiguation/redirect page).`);
}
const allParas = fullExtract.split(/\n{2,}/).map(s => s.trim()).filter(Boolean);
const paras = paragraphsCap > 0 ? allParas.slice(0, paragraphsCap) : allParas;
return [{
title: page.title,
description: page.description || '',
pageId: page.pageid ?? null,
paragraphs: paras.length,View on GitHub (pinned to 49907e53dc)
Solutions
- Read the info text in the message — it names the exact MediaWiki error code (e.g. invalidlang, ratelimited) and fix the corresponding argument
- Verify the --lang code is a valid Wikipedia language (test https://<lang>.wikipedia.org in a browser)
- Retry after a delay if the code indicates rate limiting
- Update opencli if the error persists, as API params may have changed
Example fix
// before opencli wikipedia page "Earth" --lang xx // after opencli wikipedia page "Earth" --lang en
Defensive patterns
Strategy: try-catch
Validate before calling
const lang = 'en';
if (!/^[a-z-]{2,8}$/.test(lang)) throw new Error(`unsupported lang: ${lang}`); Type guard
function isApiErrorBody(d) {
return !!d && typeof d === 'object' && !!d.error && typeof (d.error.info ?? d.error.code) === 'string';
} Try / catch
try {
const row = await run('wikipedia page', ['Earth', '--lang', lang]);
} catch (e) {
if (String(e.message).startsWith('wikipedia API error:')) {
const info = e.message.slice('wikipedia API error:'.length);
console.error(`Wikipedia refused the request: ${info}`);
} else throw e;
} Prevention
- Always pass a valid --lang code
- Keep the title URL-safe (spaces as underscores)
- Back off on MediaWiki rate-limit codes
- Keep opencli updated for API param changes
When it happens
Trigger: Calling `opencli wikipedia page <title>` where wikiFetch returns 200 OK but the body is {error: {code, info}} — e.g. an invalid language code rejected by the API, malformed title parameters, or MediaWiki-level rate limiting/unrecognized parameter values.
Common situations: Typo in --lang producing an unsupported language code, special characters in titles breaking query params, hitting api.php while rate-limited by shared IP, or a MediaWiki API deprecation changing accepted params.
Related errors
- ${label} returned HTTP ${resp.status}: ${summarizeApiError(p
- arXiv API HTTP ${resp.status}
- 获取视频分P信息失败: ${error?.message || error}
- 获取视频信息失败: ${err?.message || err}
- 获取视频播放信息失败: ${err?.message || err}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e6a919b7e7b91f25.
Report an issue: GitHub.