{"record":{"id":"5087d57036bb4ab2","repo":"jackwener/OpenCLI","slug":"coingecko-limit-must-be-a-positive-integer","errorCode":null,"errorMessage":"coingecko limit must be a positive integer","messagePattern":"coingecko limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/coingecko/categories.js","lineNumber":33,"sourceCode":"    domain: 'api.coingecko.com',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'sort', default: 'market_cap_desc', help: `Sort order (${ORDER_OPTIONS.join(' / ')})` },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of categories (1-100; CoinGecko returns ~120 max)' },\n    ],\n    columns: ['rank', 'id', 'name', 'marketCap', 'volume24h', 'marketCapChange24hPct', 'top3Coins'],\n    func: async (args) => {\n        const sort = String(args.sort ?? 'market_cap_desc').trim().toLowerCase();\n        if (!ORDER_OPTIONS.includes(sort)) {\n            throw new ArgumentError(\n                `coingecko sort \"${args.sort}\" is not supported`,\n                `Supported sorts: ${ORDER_OPTIONS.join(', ')}`,\n            );\n        }\n        const limit = Number(args.limit ?? 20);\n        if (!Number.isInteger(limit) || limit <= 0) {\n            throw new ArgumentError('coingecko limit must be a positive integer');\n        }\n        if (limit > 100) {\n            throw new ArgumentError('coingecko limit must be <= 100');\n        }\n        const url = `https://api.coingecko.com/api/v3/coins/categories?order=${encodeURIComponent(sort)}`;\n        let resp;\n        try {\n            resp = await fetch(url, { headers: { 'User-Agent': 'Mozilla/5.0' } });\n        }\n        catch (err) {\n            throw new CommandExecutionError(`coingecko categories request failed: ${err?.message ?? err}`);\n        }\n        if (resp.status === 429) {\n            throw new CommandExecutionError(\n                'coingecko returned HTTP 429 (rate limited)',\n                'Free tier allows ~30 calls/min. Wait and retry.',\n            );\n        }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/coingecko/categories.js#L15-L51","documentation":"The CLI validates --limit as a positive integer before calling the CoinGecko API. Number(args.limit) must be an integer > 0; otherwise ArgumentError is thrown. Note non-integer numbers and non-numeric strings both fail this check.","triggerScenarios":"--limit 0, --limit -5, --limit abc, or a float like --limit 2.5 on clis/coingecko/categories.js.","commonSituations":"Scripting the CLI with an unvalidated variable; typos in a shell script; passing a computed value that became NaN or fractional.","solutions":["Pass a whole number >= 1, e.g. --limit 20","Omit --limit to use the default of 20","Validate/clamp the limit value in the calling script before invoking the CLI"],"exampleFix":"// before\nnode categories.js --limit 0\n// after\nnode categories.js --limit 20","handlingStrategy":"validation","validationCode":"const limit = Number(args.limit ?? 20);\nif (!Number.isInteger(limit) || limit <= 0) {\n  throw new Error('coingecko limit must be a positive integer');\n}","typeGuard":"function isValidLimit(v) {\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0;\n}","tryCatchPattern":"try {\n  await runCategories({ limit });\n} catch (err) {\n  if (err instanceof ArgumentError) console.error('Bad --limit:', err.message);\n  else throw err;\n}","preventionTips":["Quote/validate numeric CLI args in shell scripts","Coerce and check Number.isInteger before passing user input","Omit --limit to accept the safe default of 20"],"tags":["argument-error","validation","cli","coingecko"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}