{"record":{"id":"13f572cb20debc64","repo":"jackwener/OpenCLI","slug":"paragraphs-must-be-a-non-negative-integer-0-ful","errorCode":null,"errorMessage":"paragraphs must be a non-negative integer (0 = full article)","messagePattern":"paragraphs must be a non-negative integer \\(0 = full article\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/wikipedia/page.js","lineNumber":38,"sourceCode":"    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');\n        url.searchParams.set('titles', title);\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'User-Agent': 'opencli/1.0 (+https://github.com/jackwener/opencli)',\n                    'Accept': 'application/json',","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wikipedia/page.js#L20-L56","documentation":"The optional paragraphs argument caps the article extract to its first N paragraphs; 0 means full article. The value is coerced with Number() and must be a non-negative integer — anything else (negative, fractional, NaN, non-numeric string) throws this ArgumentError.","triggerScenarios":"Passing --paragraphs -1 or a negative number to disable capping (0 is the correct 'no cap' value); passing a float like 2.5; passing a non-numeric string like 'all' or '10x'; leaving a NaN-producing value such as an empty string that Number() coerces from an invalid input.","commonSituations":"Scripts substituting '-1' or 'none' for 'unlimited'; users copying flags from other tools that use -1 as 'all'; config files storing the cap as \"\" or null-adjacent strings.","solutions":["Pass a non-negative integer (0 for the full article)","Fix shell/config values so they are numeric (e.g. '5', '0')","Drop the flag entirely — the default is 0 (full article)"],"exampleFix":"// before\nopencli wikipedia page \"Transformer\" --paragraphs -1\n// after\nopencli wikipedia page \"Transformer\" --paragraphs 0  # 0 = full article","handlingStrategy":"validation","validationCode":"const cap = Number(args.paragraphs ?? 0);\nif (!Number.isInteger(cap) || cap < 0) throw new Error('paragraphs must be a non-negative integer (0 = full)');","typeGuard":"function isParagraphCap(v) { const n = Number(v ?? 0); return Number.isInteger(n) && n >= 0; }","tryCatchPattern":"try {\n  return await pageCommand(args);\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('paragraphs')) {\n    return await pageCommand({ ...args, paragraphs: 0 }); // fall back to full article\n  }\n  throw err;\n}","preventionTips":["Remember 0 means 'no cap' — never use -1 for unlimited","Coerce and validate the value before passing to the CLI","Sanitize config-driven values to integers","Omit the flag when you want the default (full article)"],"tags":["argument-error","validation","wikipedia","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}