jackwener/OpenCLI · error · ArgumentError
wikipedia page title cannot be empty
Error message
wikipedia page title cannot be empty
What it means
The `wikipedia page` command requires a positional article title. If args.title is missing, null, or only whitespace after trimming, the command's func throws an ArgumentError immediately before any network call, because a title-less query cannot produce a meaningful API request.
Source
Thrown at clis/wikipedia/page.js:30
cli({
site: 'wikipedia',
name: 'page',
access: 'read',
description: 'Full plain-text extract of a Wikipedia article (optional paragraph cap).',
domain: 'wikipedia.org',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'title', positional: true, required: true, type: 'string', help: 'Article title (e.g. "Transformer (machine learning model)")' },
{ name: 'lang', type: 'string', default: 'en', help: 'Language code (en, zh, ja, de, ...).' },
{ name: 'paragraphs', type: 'int', default: 0, help: 'Cap to first N paragraphs (0 = full article).' },
],
columns: ['title', 'description', 'pageId', 'paragraphs', 'extract', 'url'],
func: async (args) => {
const title = String(args.title ?? '').trim();
if (!title) {
throw new ArgumentError('wikipedia page title cannot be empty');
}
const lang = String(args.lang ?? 'en').trim().toLowerCase();
if (!/^[a-z]{2,3}(?:-[a-z0-9]+)?$/.test(lang)) {
throw new ArgumentError(`wikipedia lang must be a language code like en, zh, ja (got "${args.lang}")`);
}
const paragraphsCap = Number(args.paragraphs ?? 0);
if (!Number.isInteger(paragraphsCap) || paragraphsCap < 0) {
throw new ArgumentError('paragraphs must be a non-negative integer (0 = full article)');
}
const url = new URL(`https://${lang}.wikipedia.org/w/api.php`);
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');View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty article title as the first positional argument
- Check the variable feeding the title is defined and non-blank before invoking
- Run `opencli wikipedia search <term>` first to find the exact title
Example fix
// before
await run(['wikipedia', 'page', title ?? '']);
// after
if (!title?.trim()) throw new Error('title is required');
await run(['wikipedia', 'page', title.trim()]); Defensive patterns
Strategy: validation
Validate before calling
const title = String(args.title ?? '').trim();
if (!title) throw new Error('wikipedia page requires a non-empty title'); Type guard
function hasTitle(args) { return typeof args.title === 'string' && args.title.trim().length > 0; } Try / catch
try {
return await pageCommand(args);
} catch (err) {
if (err instanceof ArgumentError) {
console.error(`usage: wikipedia page <title> [--lang <code>] -- ${err.message}`);
return null;
}
throw err;
} Prevention
- Always supply the positional title argument
- Trim and check variables feeding the title before invoking
- Run `wikipedia search` first to obtain exact titles
- Guard shell variables with ${VAR:?unset} in scripts
When it happens
Trigger: Invoking the command without the positional title argument; passing an empty string or whitespace-only title programmatically; a variable holding the title being undefined/null at call time.
Common situations: Shell variable expansion producing an empty value ($TITLE unset); scripting the command and forgetting the positional arg; piping pipelines where an upstream step emitted nothing.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- paragraphs must be a non-negative integer (0 = full article)
- series_id must be a non-empty value
- Invalid Chess.com username "${value}" Usernames are 3-25 cha
- coingecko derivatives limit must be a positive integer
- limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8482aff91924c99c.
Report an issue: GitHub.