jackwener/OpenCLI · warning · EmptyResultError

wikipedia page

Error message

wikipedia page

What it means

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.

Source

Thrown at clis/wikipedia/page.js:77

        } 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,
            extract: paras.join('\n\n'),
            url: page.fullurl || `https://${lang}.wikipedia.org/wiki/${encodeURIComponent(page.title.replace(/ /g, '_'))}`,
        }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use `opencli wikipedia search <keyword>` to find a concrete article title, then page it
  2. Disambiguate the title yourself (e.g. "Mercury (planet)" instead of "Mercury")
  3. Try a different --lang where the article has a full lead section

Example fix

// before
opencli wikipedia page "Mercury"
// after
opencli wikipedia search Mercury
opencli wikipedia page "Mercury (planet)"
Defensive patterns

Strategy: fallback

Type guard

function hasExtract(page) {
  return !!page && typeof page.extract === 'string' && page.extract.trim().length > 0;
}

Try / catch

try {
  const rows = await run('wikipedia page', [title, '--lang', lang]);
} catch (e) {
  if (/no plain-text extract/.test(e.message)) {
    const rows = await run('wikipedia search', [title, '--lang', lang]);
    console.log('Disambiguation page; matching articles:', rows);
  } else throw e;
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/9a3fa689df9599ce. Report an issue: GitHub.