{"record":{"id":"a5951fa304472f6a","repo":"jackwener/OpenCLI","slug":"index-must-be-a-positive-integer-a5951f","errorCode":null,"errorMessage":"index must be a positive integer","messagePattern":"index must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/comment.js","lineNumber":25,"sourceCode":"    domain: 'www.instagram.com',\n    args: [\n        {\n            name: 'username',\n            required: true,\n            positional: true,\n            help: 'Username of the post author',\n        },\n        { name: 'text', required: true, positional: true, help: 'Comment text' },\n        { name: 'index', type: 'int', default: 1, help: 'Post index (1 = most recent)' },\n    ],\n    columns: ['status', 'user', 'text'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const username = \\${{ args.username | json }};\n  const commentText = \\${{ args.text | json }};\n  const idx = \\${{ args.index }} - 1;\n  if (!Number.isInteger(idx) || idx < 0) throw new Error('index must be a positive integer');\n  const headers = { 'X-IG-App-ID': '936619743392459' };\n  const opts = { credentials: 'include', headers };\n  async function readInstagramJson(response, label) {\n    try {\n      return await response.json();\n    } catch {\n      throw new Error(label + ' returned invalid JSON');\n    }\n  }\n  function getPostFromFeed(feed, label) {\n    if (!feed || typeof feed !== 'object' || !Array.isArray(feed.items)) {\n      throw new Error(label + ' returned malformed items payload');\n    }\n    if (idx >= feed.items.length) throw new Error('Post index ' + (idx + 1) + ' not found');\n    const post = feed.items[idx];\n    const pkRaw = post?.pk ?? post?.id;\n    const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');\n    if (!/^\\\\d+$/.test(pk)) throw new Error(label + ' returned malformed post row');","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/comment.js#L7-L43","documentation":"Inside the browser-evaluated pipeline, the requested post index (after converting to 1-based offset idx = index - 1) is not an integer or is negative. The CLI validates args.index before fetching so that only a valid positive integer selects a post from the user's feed.","triggerScenarios":"Calling the comment command with index=0, a negative number, a float (e.g. 2.5), or a non-numeric string that resolves to NaN, making idx not a non-negative integer.","commonSituations":"Copy-pasting a 0-based index from another tool; passing '1st' or an empty --index flag; a config file where index is a string like \"3\" that fails templating into the pipeline correctly.","solutions":["Pass a whole-number index starting at 1 (1 = most recent post)","Strip whitespace and validate with Number.isInteger(Number(index)) && Number(index) >= 1 before invoking","Fix the config/CLI flag so index is a number, not a string with units or formatting"],"exampleFix":"// before\ninstagram comment --username target_user --index 0 --text \"nice\"\n// after\ninstagram comment --username target_user --index 1 --text \"nice\"","handlingStrategy":"validation","validationCode":"function isValidIndex(n) {\n  return Number.isInteger(Number(n)) && Number(n) >= 1;\n}\nif (!isValidIndex(args.index)) throw new Error('index must be a whole number >= 1');","typeGuard":"const isPositiveInt = (v) => Number.isInteger(v) && v >= 1;","tryCatchPattern":"try {\n  await commentOnPost({ username, index, text });\n} catch (e) {\n  if (/index must be a positive integer/.test(e.message)) {\n    console.error('Pass --index as a whole number starting at 1');\n  } else throw e;\n}","preventionTips":["Always pass index as a 1-based whole number","Validate CLI flags before invoking","Avoid copying 0-based indices from other tools","Don't pass strings with units or formatting as index"],"tags":["instagram","validation","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}