{"record":{"id":"990b5fa35e3853e3","repo":"jackwener/OpenCLI","slug":"index-must-be-a-positive-integer-990b5f","errorCode":null,"errorMessage":"index must be a positive integer","messagePattern":"index must be a positive integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"clis/instagram/unsave.js","lineNumber":23,"sourceCode":"    access: 'write',\n    description: 'Unsave (remove bookmark) an Instagram post',\n    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: 'index', type: 'int', default: 1, help: 'Post index (1 = most recent)' },\n    ],\n    columns: ['status', 'user', 'post'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const username = \\${{ args.username | 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":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/unsave.js#L5-L41","documentation":"The unsave command's injected browser script converts the 1-based --index argument to a 0-based idx and validates it before use. If args.index is not a positive integer (0, negative, fractional, or non-numeric), the script throws immediately. This is an argument-validation guard, not a network failure.","triggerScenarios":"Calling unsave with --index 0, --index -1, --index 2.5, or a non-numeric value; the check `!Number.isInteger(idx) || idx < 0` fails where idx = index - 1.","commonSituations":"Typing 0-based index by habit (CLI expects 1-based); passing a string/empty value from a script; off-by-one confusion when the saved post is the first in the list.","solutions":["Pass a 1-based positive integer, e.g. --index 1 for the first post.","Check the value is an integer greater than 0 before invoking.","If scripting, coerce with Number() and Number.isInteger() before calling."],"exampleFix":"// before\nnpx cli instagram unsave --username someuser --index 0\n// after\nnpx cli instagram unsave --username someuser --index 1","handlingStrategy":"validation","validationCode":"const idx = Number(index);\nif (!Number.isInteger(idx) || idx < 1) throw new Error('index must be a positive integer, got: ' + index);","typeGuard":"const isValidIndex = (n) => Number.isInteger(n) && n >= 1;","tryCatchPattern":null,"preventionTips":["Remember the CLI index is 1-based","Validate numeric CLI args in wrapper scripts","Coerce string args with Number() before passing"],"tags":["validation","arguments","instagram"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}