{"record":{"id":"8482aff91924c99c","repo":"jackwener/OpenCLI","slug":"wikipedia-page-title-cannot-be-empty","errorCode":null,"errorMessage":"wikipedia page title cannot be empty","messagePattern":"wikipedia page title cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/wikipedia/page.js","lineNumber":30,"sourceCode":"\ncli({\n    site: 'wikipedia',\n    name: 'page',\n    access: 'read',\n    description: 'Full plain-text extract of a Wikipedia article (optional paragraph cap).',\n    domain: 'wikipedia.org',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'title', positional: true, required: true, type: 'string', help: 'Article title (e.g. \"Transformer (machine learning model)\")' },\n        { name: 'lang', type: 'string', default: 'en', help: 'Language code (en, zh, ja, de, ...).' },\n        { name: 'paragraphs', type: 'int', default: 0, help: 'Cap to first N paragraphs (0 = full article).' },\n    ],\n    columns: ['title', 'description', 'pageId', 'paragraphs', 'extract', 'url'],\n    func: async (args) => {\n        const title = String(args.title ?? '').trim();\n        if (!title) {\n            throw new ArgumentError('wikipedia page title cannot be empty');\n        }\n        const lang = String(args.lang ?? 'en').trim().toLowerCase();\n        if (!/^[a-z]{2,3}(?:-[a-z0-9]+)?$/.test(lang)) {\n            throw new ArgumentError(`wikipedia lang must be a language code like en, zh, ja (got \"${args.lang}\")`);\n        }\n        const paragraphsCap = Number(args.paragraphs ?? 0);\n        if (!Number.isInteger(paragraphsCap) || paragraphsCap < 0) {\n            throw new ArgumentError('paragraphs must be a non-negative integer (0 = full article)');\n        }\n\n        const url = new URL(`https://${lang}.wikipedia.org/w/api.php`);\n        url.searchParams.set('action', 'query');\n        url.searchParams.set('format', 'json');\n        url.searchParams.set('formatversion', '2');\n        url.searchParams.set('prop', 'extracts|info|description');\n        url.searchParams.set('inprop', 'url');\n        url.searchParams.set('explaintext', '1');\n        url.searchParams.set('redirects', '1');","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikipedia/page.js#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait run(['wikipedia', 'page', title ?? '']);\n// after\nif (!title?.trim()) throw new Error('title is required');\nawait run(['wikipedia', 'page', title.trim()]);","handlingStrategy":"validation","validationCode":"const title = String(args.title ?? '').trim();\nif (!title) throw new Error('wikipedia page requires a non-empty title');","typeGuard":"function hasTitle(args) { return typeof args.title === 'string' && args.title.trim().length > 0; }","tryCatchPattern":"try {\n  return await pageCommand(args);\n} catch (err) {\n  if (err instanceof ArgumentError) {\n    console.error(`usage: wikipedia page <title> [--lang <code>] -- ${err.message}`);\n    return null;\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["argument-error","validation","wikipedia","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}