{"record":{"id":"de0e2a7ab10663be","repo":"jackwener/OpenCLI","slug":"bbc-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"bbc ${label} must be a positive integer","messagePattern":"bbc (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/bbc/utils.js","lineNumber":47,"sourceCode":"    let m;\n    while ((m = re.exec(String(xml || ''))) !== null) {\n        const block = m[1];\n        out.push({\n            title: decodeHtmlEntities(extractRssTag(block, 'title')).trim(),\n            description: decodeHtmlEntities(extractRssTag(block, 'description')).trim(),\n            link: decodeHtmlEntities(extractRssTag(block, 'link')).trim(),\n            pubDate: decodeHtmlEntities(extractRssTag(block, 'pubDate')).trim(),\n            guid: decodeHtmlEntities(extractRssTag(block, 'guid')).trim(),\n        });\n    }\n    return out;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`bbc ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`bbc ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport async function bbcFetchRss(path, label) {\n    const url = `${BBC_FEED_BASE}/${path}`;\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/rss+xml, application/xml' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that feeds.bbci.co.uk is reachable from this network.',\n        );","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bbc/utils.js#L29-L65","documentation":"ArgumentError from `requireBoundedInt` when the provided value is not an integer greater than 0 (NaN, float, string like 'abc', zero, or negative). The helper coerces to Number via `Number(raw)` and enforces integer positivity before checking the upper bound.","triggerScenarios":"`bbc topic --limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or any non-numeric string that fails `Number.isInteger(Number(raw))`.","commonSituations":"Typos in CLI flags, passing default/placeholder text instead of a number, copy-pasting values with units ('20 items'), scripts passing undefined wrapped as the string 'undefined'.","solutions":["Pass a positive integer, e.g. `--limit 20`.","Strip units/whitespace before passing numeric arguments.","Validate the argument in your script with Number.isInteger before calling the CLI.","Omit the flag to use the default (20)."],"exampleFix":"// before\nawait cli.run(['bbc','topic','technology','--limit','abc']);\n// after\nawait cli.run(['bbc','topic','technology','--limit','20']);","handlingStrategy":"validation","validationCode":"function assertLimit(v){ const n = Number(v); if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer'); return n; }","typeGuard":"const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0 && String(v).trim() !== '';","tryCatchPattern":"try {\n  const items = await cli.run(['bbc','topic', topic, '--limit', String(limit)]);\n} catch (e) {\n  if (e.name === 'ArgumentError' && /positive integer/.test(e.message)) {\n    limit = 20; // fall back to default and retry\n  }\n}","preventionTips":["Coerce and validate numeric flags before passing them","Omit --limit to use the default of 20","Beware string values like 'undefined' or '20 '","Use Number.isInteger in wrapper scripts"],"tags":["bbc","validation","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}