{"record":{"id":"4d53a54dd7ed50e3","repo":"jackwener/OpenCLI","slug":"post-index-idx-1-not-found-4d53a5","errorCode":null,"errorMessage":"Post index ' + (idx + 1) + ' not found","messagePattern":"Post index ' \\+ \\(idx \\+ 1\\) \\+ ' not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"clis/instagram/unsave.js","lineNumber":37,"sourceCode":"        { 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');\n    const caption = typeof post?.caption?.text === 'string' ? post.caption.text.substring(0, 60) : '';\n    return { pk, caption };\n  }\n  function assertOkStatus(payload, label) {\n    if (!payload || typeof payload !== 'object' || payload.status !== 'ok') {\n      throw new Error(label + ' returned no success evidence');\n    }\n  }\n\n  // web_profile_info answers HTTP 400 for business accounts; feed-by-username needs no user id. See #2234.\n  const r1 = await fetch('https://www.instagram.com/api/v1/feed/user/' + encodeURIComponent(username) + '/username/?count=' + (idx + 1), opts);\n  if (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');\n  const { pk, caption } = getPostFromFeed(await readInstagramJson(r1, 'Instagram feed-by-username'), 'Instagram feed-by-username');\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/unsave.js#L19-L55","documentation":"The 1-based post index supplied is beyond the number of items Instagram returned in the feed. The script throws with the 1-based index so you can match what you passed. Instagram only returns as many posts as exist (bounded by ?count=).","triggerScenarios":"unsave --index 5 when the user has only 3 posts, or the feed returned fewer items than requested (private/restricted visibility).","commonSituations":"Saved list shrank since the user last checked; guessing an index without listing posts first; account deleted posts.","solutions":["Lower --index to a value within the account's post count.","List the user's posts first to find the correct 1-based index.","Confirm the account still has that many posts."],"exampleFix":"// before\nnpx cli instagram unsave --username someuser --index 12\n// after\nnpx cli instagram user someuser   # list posts to pick a valid index\nnpx cli instagram unsave --username someuser --index 3","handlingStrategy":"validation","validationCode":"const postCount = await getPostCount(username);\nif (index > postCount) throw new Error(`index ${index} exceeds ${postCount} posts`);","typeGuard":null,"tryCatchPattern":"try {\n  await cli.unsave(user, index);\n} catch (e) {\n  if (e.message.includes('not found')) {\n    const posts = await cli.user(user);\n    console.log('Valid indices:', posts.map(p => p.index));\n  } else throw e;\n}","preventionTips":["List posts first to learn the valid 1-based range","Re-check post counts before each unsave batch","Remember indices shift when posts are deleted"],"tags":["instagram","validation","arguments"],"backgroundTag":"index-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}