{"record":{"id":"7485f2fce849d2ba","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-7485f2","errorCode":null,"errorMessage":"limit must be a positive integer","messagePattern":"limit must be a positive integer","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/instagram/followers.js","lineNumber":19,"sourceCode":"import { cli } from '@jackwener/opencli/registry';\nimport { buildResolveInstagramUserIdJs } from './_shared/user-id.js';\ncli({\n    site: 'instagram',\n    name: 'followers',\n    access: 'read',\n    description: 'List followers of an Instagram user',\n    domain: 'www.instagram.com',\n    args: [\n        { name: 'username', required: true, positional: true, help: 'Instagram username' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of followers' },\n    ],\n    columns: ['rank', 'username', 'name', 'verified', 'private'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const username = \\${{ args.username | json }};\n  const limit = \\${{ args.limit }};\n  if (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be a positive integer');\n  const headers = { 'X-IG-App-ID': '936619743392459' };\n  const opts = { credentials: 'include', headers };\n\n  ${buildResolveInstagramUserIdJs()}\n\n  const r2 = await fetch(\n    'https://www.instagram.com/api/v1/friendships/' + userId + '/followers/?count=' + limit,\n    opts\n  );\n  if (!r2.ok) throw new Error('Failed to fetch followers: HTTP ' + r2.status);\n  const d2 = await r2.json();\n  if (!d2 || typeof d2 !== 'object' || !Array.isArray(d2.users)) {\n    throw new Error('Instagram followers returned malformed users payload');\n  }\n  return d2.users.slice(0, limit).map((u, i) => {\n    if (!u || typeof u !== 'object') {\n      throw new Error('Instagram followers returned malformed user row');\n    }","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/followers.js#L1-L37","documentation":"Input validation in the followers CLI's embedded page script: the --limit argument must be a positive integer. Because the arg is interpolated directly into the evaluate script, a non-integer (float, string, 0, negative) reaches Number.isInteger(limit) and the script aborts before any network call. It guards the count= query parameter and the slice(0, limit).","triggerScenarios":"Running the followers command with limit=0, a negative number, a decimal like 2.5, or a value interpolated as a non-number (e.g. quoted string, NaN from a bad int parse).","commonSituations":"Passing --limit 0 expecting 'unlimited'; passing a float; passing a huge number that overflows or a string in a wrapper script; forgetting the flag and some wrapper supplies an empty value.","solutions":["Pass a positive integer, e.g. --limit 20.","In wrapper scripts, coerce with Math.trunc/parseInt and check Number.isInteger(n) && n > 0 before invoking.","Use the default (20) by omitting the flag if you don't need a custom count.","Clamp upper bounds to what you need; Instagram caps page counts server-side anyway."],"exampleFix":"// before\nopencli instagram followers someuser --limit 0\n// after\nconst limit = Number(rawLimit);\nif (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be a positive integer');\nopencli instagram followers someuser --limit 20","handlingStrategy":"validation","validationCode":"function parseLimit(raw) {\n  const n = typeof raw === 'number' ? raw : Number.parseInt(raw, 10);\n  if (!Number.isInteger(n) || n < 1) throw new Error('limit must be a positive integer');\n  return n;\n}\n// run before invoking the CLI","typeGuard":"function isPositiveInt(v) { return Number.isInteger(v) && v >= 1; }","tryCatchPattern":"try {\n  await cli.followers(username, limit);\n} catch (e) {\n  if (String(e.message).includes('limit must be')) {\n    console.error(`Bad --limit value: ${JSON.stringify(limit)}; use a positive integer`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Validate/coerce numeric CLI args at the wrapper boundary with parseInt/Math.trunc.","Never pass 0 or floats expecting 'all' — use a large finite integer instead.","Keep numbers as numbers through templating/interpolation, not strings.","Add a unit test for arg parsing covering 0, negative, float, and string inputs."],"tags":["validation","argument-parsing","instagram"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}