{"record":{"id":"9a3fa689df9599ce","repo":"jackwener/OpenCLI","slug":"wikipedia-page","errorCode":null,"errorMessage":"wikipedia page","messagePattern":"wikipedia page","errorType":"error_code","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/wikipedia/page.js","lineNumber":77,"sourceCode":"        } 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,\n            extract: paras.join('\\n\\n'),\n            url: page.fullurl || `https://${lang}.wikipedia.org/wiki/${encodeURIComponent(page.title.replace(/ /g, '_'))}`,\n        }];\n    },\n});","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikipedia/page.js#L59-L95","documentation":"EmptyResultError with resource 'wikipedia page' thrown when the article exists on <lang>.wikipedia.org but its plain-text extract is empty or whitespace-only. The library treats an existing-but-unextractable page (typically a disambiguation or redirect page) as an empty result rather than returning blank output.","triggerScenarios":"`opencli wikipedia page <title>` resolving to a page whose `extract` field from action=query&prop=extracts is '' after trim — disambiguation pages, pure redirect stubs, or pages that only contain non-plain-text content.","commonSituations":"Querying a title like \"Mercury (disambiguation)\" or an ambiguous short title that redirects; non-English wikis where the target page is a stub with no lead paragraph.","solutions":["Use `opencli wikipedia search <keyword>` to find a concrete article title, then page it","Disambiguate the title yourself (e.g. \"Mercury (planet)\" instead of \"Mercury\")","Try a different --lang where the article has a full lead section"],"exampleFix":"// before\nopencli wikipedia page \"Mercury\"\n// after\nopencli wikipedia search Mercury\nopencli wikipedia page \"Mercury (planet)\"","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function hasExtract(page) {\n  return !!page && typeof page.extract === 'string' && page.extract.trim().length > 0;\n}","tryCatchPattern":"try {\n  const rows = await run('wikipedia page', [title, '--lang', lang]);\n} catch (e) {\n  if (/no plain-text extract/.test(e.message)) {\n    const rows = await run('wikipedia search', [title, '--lang', lang]);\n    console.log('Disambiguation page; matching articles:', rows);\n  } else throw e;\n}","preventionTips":["Avoid disambiguation titles (contain \"(disambiguation)\")","Prefer specific titles like \"Mercury (planet)\"","Search first when the term is ambiguous"],"tags":["empty-result","wikipedia","content"],"backgroundTag":"empty-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}