{"record":{"id":"ce92af534eaae65f","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-ce92af","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/github-trending/repos.js","lineNumber":122,"sourceCode":"    domain: 'github.com',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'since', type: 'string', default: 'daily', help: 'Time range: daily / weekly / monthly' },\n        { name: 'language', type: 'string', default: '', help: 'Filter by programming language slug, e.g. python, rust, \"c++\"' },\n        { name: 'limit', type: 'int', default: 25, help: 'Number of repositories to return (max 25)' },\n    ],\n    columns: ['rank', 'repo', 'description', 'language', 'stars', 'forks', 'starsSince', 'url'],\n    func: async (args) => {\n        const sinceKey = String(args.since ?? 'daily').toLowerCase();\n        const since = SINCE[sinceKey];\n        if (!since) {\n            throw new ArgumentError(`Unknown --since \"${sinceKey}\". Valid: ${Object.keys(SINCE).join(', ')}`);\n        }\n\n        const n = Number(args.limit ?? 25);\n        if (!Number.isInteger(n) || n <= 0) {\n            throw new ArgumentError('--limit must be a positive integer');\n        }\n        if (n > 25) {\n            throw new ArgumentError('--limit must be <= 25 (GitHub Trending lists at most 25 repositories)');\n        }\n        const limit = n;\n\n        const language = String(args.language ?? '').trim();\n        const path = language ? `/trending/${encodeURIComponent(language)}` : '/trending';\n        const url = new URL(`https://github.com${path}`);\n        url.searchParams.set('since', since);\n\n        let resp;\n        try {\n            resp = await fetch(url, {\n                headers: {\n                    'User-Agent': 'Mozilla/5.0 (compatible; opencli/github-trending)',\n                    Accept: 'text/html',\n                },","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/github-trending/repos.js#L104-L140","documentation":"The `--limit` option of `opencli github-trending repos` must be a positive integer (default 25). Non-integer, zero, negative, or non-numeric values throw this ArgumentError. Validation runs after --since parsing and before any HTTP request.","triggerScenarios":"Passing `--limit 0`, `--limit -5`, `--limit abc`, `--limit 2.5`, or a value that `Number()` coerces to NaN/non-integer.","commonSituations":"Computing the limit from a shell variable that ends up empty (`--limit \"\"` -> NaN); using a float from a config; sign/typo errors like `--limit -1`; expecting 0 to mean 'unlimited' (it does not).","solutions":["Pass a positive integer between 1 and 25, e.g. --limit 10","Omit --limit entirely to use the default of 25","Fix the script logic producing a non-integer/empty value before invoking the CLI"],"exampleFix":"// before\nconst lim = process.env.LIMIT; // \"\" -> NaN\nopencli github-trending repos --limit \"$lim\"\n// after\nconst lim = process.env.LIMIT || \"25\";\nopencli github-trending repos --limit \"$lim\"","handlingStrategy":"validation","validationCode":"function validateLimit(v) {\n  const n = Number(v ?? 25);\n  if (!Number.isInteger(n) || n <= 0) throw new Error('--limit must be a positive integer');\n  return n;\n}","typeGuard":"function isArgumentError(e) { return e instanceof Error && e.name === 'ArgumentError'; }","tryCatchPattern":"try {\n  await run(['opencli', 'github-trending', 'repos', '--limit', String(limit)]);\n} catch (e) {\n  if (e.name === 'ArgumentError') { console.error(e.message); process.exitCode = 2; }\n  else throw e;\n}","preventionTips":["Coerce and validate limit as a positive integer in scripts before invoking","Treat empty env/variables as the default (25) rather than passing them raw","Remember 0 is invalid — there is no 'unlimited' via --limit"],"tags":["argument-validation","cli","input-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}