{"record":{"id":"cb8309321cc5f648","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer","errorCode":null,"errorMessage":"limit must be a positive integer","messagePattern":"limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/aibase/news.js","lineNumber":12,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError, getErrorMessage } from '@jackwener/opencli/errors';\n\nconst AIBASE_DAILY_URL = 'https://www.aibase.com/zh/daily';\nconst DEFAULT_LIMIT = 20;\nconst MAX_LIMIT = 50;\n\nfunction normalizeLimit(value) {\n    const raw = value ?? DEFAULT_LIMIT;\n    const limit = Number(raw);\n    if (!Number.isInteger(limit) || limit <= 0) {\n        throw new ArgumentError('limit must be a positive integer', `Example: opencli aibase news --limit ${DEFAULT_LIMIT}`);\n    }\n    if (limit > MAX_LIMIT) {\n        throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli aibase news --limit ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\nfunction normalizeText(value) {\n    return String(value ?? '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction buildExtractAibaseNewsJs() {\n    return `\n      (() => {\n        const anchors = Array.from(document.querySelectorAll('.bg-white .grid a[href], a[href*=\"/zh/daily/\"]'))\n          .filter((anchor) => {\n            const href = anchor.getAttribute('href') || '';\n            const text = (anchor.innerText || anchor.textContent || '').trim();","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/aibase/news.js#L1-L30","documentation":"normalizeLimit in clis/aibase/news.js validates the --limit argument for the aibase news command and throws an ArgumentError when the value is not a positive integer (zero, negative, non-numeric, or fractional). The error carries an example usage string showing the default limit (20).","triggerScenarios":"Running `opencli aibase news --limit 0`, `--limit -3`, `--limit abc`, or `--limit 2.5`.","commonSituations":"Typing 0 assuming it means 'unlimited', scripts substituting empty strings into the flag, locale-formatted numbers ('2,5' or '10件'), and copy-paste errors with trailing characters.","solutions":["Pass a positive integer between 1 and 50, e.g. opencli aibase news --limit 20.","Omit --limit to use the default of 20.","If passing programmatically, validate first: Number.isInteger(Number(v)) && Number(v) > 0."],"exampleFix":"// before\nopencli aibase news --limit 0\n// after\nopencli aibase news --limit 20","handlingStrategy":"validation","validationCode":"const n = Number(limitArg);\nif (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer');","typeGuard":"function isPositiveInt(v) {\n  return typeof v === 'number' && Number.isInteger(v) && v > 0;\n}","tryCatchPattern":"try {\n  await runCommand(['aibase', 'news', '--limit', String(n)]);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message === 'limit must be a positive integer') {\n    console.error('Invalid --limit; falling back to default 20');\n  } else throw e;\n}","preventionTips":["Validate CLI ints with Number.isInteger before passing","Never pass 0 or negatives expecting 'unlimited' behavior","Avoid locale-formatted numeric strings","Quote shell variables used in flags"],"tags":["cli","argument-validation","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}