{"record":{"id":"e6a919b7e7b91f25","repo":"jackwener/OpenCLI","slug":"wikipedia-api-error-data-error-info-data-err","errorCode":null,"errorMessage":"wikipedia API error: ${data.error.info || data.error.code}","messagePattern":"wikipedia API error: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/wikipedia/page.js","lineNumber":72,"sourceCode":"                headers: {\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                    'Accept': 'application/json',\n                },\n            });\n        } catch (error) {\n            throw new CommandExecutionError(`wikipedia page request failed: ${error?.message || error}`);\n        }\n        if (!resp.ok) {\n            throw new CommandExecutionError(`wikipedia page failed: HTTP ${resp.status}`);\n        }\n        let data;\n        try {\n            data = await resp.json();\n        } catch (error) {\n            throw new CommandExecutionError(`wikipedia returned malformed JSON: ${error?.message || error}`);\n        }\n        if (data?.error) {\n            throw new CommandExecutionError(`wikipedia API error: ${data.error.info || data.error.code}`);\n        }\n        const pages = Array.isArray(data?.query?.pages) ? data.query.pages : [];\n        const page = pages[0];\n        if (!page || page.missing) {\n            throw new EmptyResultError('wikipedia page', `No article \"${title}\" on ${lang}.wikipedia.org. Try \\`opencli wikipedia search\\` first.`);\n        }\n        const fullExtract = String(page.extract ?? '');\n        if (!fullExtract.trim()) {\n            throw new EmptyResultError('wikipedia page', `Article \"${page.title}\" exists but has no plain-text extract (likely a disambiguation/redirect page).`);\n        }\n        const allParas = fullExtract.split(/\\n{2,}/).map(s => s.trim()).filter(Boolean);\n        const paras = paragraphsCap > 0 ? allParas.slice(0, paragraphsCap) : allParas;\n\n        return [{\n            title: page.title,\n            description: page.description || '',\n            pageId: page.pageid ?? null,\n            paragraphs: paras.length,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikipedia/page.js#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nopencli wikipedia page \"Earth\" --lang xx\n// after\nopencli wikipedia page \"Earth\" --lang en","handlingStrategy":"try-catch","validationCode":"const lang = 'en';\nif (!/^[a-z-]{2,8}$/.test(lang)) throw new Error(`unsupported lang: ${lang}`);","typeGuard":"function isApiErrorBody(d) {\n  return !!d && typeof d === 'object' && !!d.error && typeof (d.error.info ?? d.error.code) === 'string';\n}","tryCatchPattern":"try {\n  const row = await run('wikipedia page', ['Earth', '--lang', lang]);\n} catch (e) {\n  if (String(e.message).startsWith('wikipedia API error:')) {\n    const info = e.message.slice('wikipedia API error:'.length);\n    console.error(`Wikipedia refused the request: ${info}`);\n  } else throw e;\n}","preventionTips":["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"],"tags":["network","api","wikipedia"],"backgroundTag":"wikipedia-api-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}