{"record":{"id":"5e586eccf131e571","repo":"jackwener/OpenCLI","slug":"post-index-not-found","errorCode":null,"errorMessage":"Post index  not found","messagePattern":"Post index  not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/save.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/save.js#L19-L55","documentation":"Thrown by `getPostFromFeed` when `idx` (the 0-based requested post position) is greater than or equal to `feed.items.length`, i.e. the user's feed returned fewer posts than the requested position. The command requests `count=<idx+1>` posts, but Instagram may return fewer (private account, deleted posts, partial feeds), leaving no item at the requested index.","triggerScenarios":"Running `instagram save <username> --index N` where the user's visible feed has fewer than N posts: index 25 on an account with 10 posts, or an index beyond what the feed endpoint returned despite the count parameter.","commonSituations":"Targeting an account with very few posts; some posts are deleted/archived or hidden (e.g. restricted content) so the feed is shorter than the profile post count; a large index (e.g. 50+) where Instagram caps or truncates the feed response.","solutions":["Lower the --index value to a position within the number of posts the profile actually shows.","Verify on instagram.com how many posts the account visibly has and pick an index within that range.","If you need an older post beyond the feed window, open the post on the web and save it manually, or paginate the feed first."],"exampleFix":"// before: account only has 12 visible posts\ninstagram save someuser --index 40\n// after\ninstagram save someuser --index 5","handlingStrategy":"validation","validationCode":"const visiblePosts = countVisiblePostsOnProfile(username); // e.g. from profile page\nif (Number(args.index) > visiblePosts) {\n  throw new Error(`--index ${args.index} exceeds the ${visiblePosts} visible posts for ${username}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await run(['instagram', 'save', username, '--index', String(i)]);\n} catch (e) {\n  if (String(e.message).includes('not found')) {\n    console.error(`Post #${i} does not exist; the feed returned fewer posts. Lower --index.`);\n  }\n  throw e;\n}","preventionTips":["Check the profile's visible post count before using a large --index.","Prefer small indexes (recent posts); old posts may fall outside the feed window.","Remember deleted/archived/restricted posts shrink the accessible feed."],"tags":["validation","range-error","instagram"],"backgroundTag":"index-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}