{"record":{"id":"86d0a14d54e8d0de","repo":"jackwener/OpenCLI","slug":"post-index-index-not-found-username-has-s","errorCode":null,"errorMessage":"Post index ${index} not found; ${username} has ${snapshot.posts.length} recent posts.","messagePattern":"Post index (.+?) not found; (.+?) has (.+?) recent posts\\.","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/instagram/_shared/post-like.js","lineNumber":150,"sourceCode":"        return {\n            code,\n            pk,\n            caption: typeof item.caption === 'string' ? item.caption : '',\n            liked: item.liked,\n        };\n    });\n    return { ownerId, posts };\n}\n\nasync function readPostSnapshot(page, username, index, command) {\n    const feed = unwrapEvaluateResult(await page.evaluate(buildReadPostsJs(username, index)));\n    return normalizeFeedSnapshot(feed, command, username);\n}\n\nfunction pickPost(snapshot, username, index, command) {\n    const post = snapshot.posts[index - 1];\n    if (!post) {\n        throw new EmptyResultError(command, snapshot.posts.length === 0\n            ? `No visible posts for ${username}; check the username and whether the account is private.`\n            : `Post index ${index} not found; ${username} has ${snapshot.posts.length} recent posts.`);\n    }\n    return post;\n}\n\nasync function confirmPersistedState(page, username, index, command, expectedPost, shouldLike) {\n    const confirmed = pickPost(await readPostSnapshot(page, username, index, command), username, index, command);\n    if (confirmed.code !== expectedPost.code || confirmed.pk !== expectedPost.pk) {\n        throw new CommandExecutionError(\n            `Instagram post feed no longer shows the expected post ${expectedPost.code} at index ${index}`,\n            'The profile feed may have re-rendered or changed order; retry after checking the post in the browser.',\n        );\n    }\n    if (confirmed.liked !== shouldLike) {\n        throw new CommandExecutionError(\n            `Instagram did not persist the ${shouldLike ? 'like' : 'unlike'} on ${expectedPost.code}`,\n            'The action may have been rejected. Retry later, or check the post in the browser.',","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/post-like.js#L132-L168","documentation":"pickPost throws EmptyResultError with this message when the requested 1-based index does not exist in a non-empty snapshot. The library resolved the profile feed successfully and found posts, but fewer than index of them, so the requested post cannot be selected.","triggerScenarios":"Calling instagram like/unlike with --index greater than the number of visible posts — e.g. --index 10 on a profile showing 6 posts — or a feed that re-rendered between snapshot reads and now shows fewer posts.","commonSituations":"Assuming a full page of 12 posts on a low-activity account; indices captured from an earlier session when the account had more posts; deleted posts or reordering (pinned posts) shrinking the visible list.","solutions":["Run the listing/read command first to see how many posts exist, then choose a valid --index","Clamp index to snapshot.posts.length in your wrapper before calling the API","Re-check whether pinned/deleted posts changed the visible count since your last run"],"exampleFix":"// before: arbitrary index\nawait setInstagramPostLike(page, { username: 'user', index: 10 }, true);\n// after: clamp to available posts\nconst maxIndex = snapshot.posts.length;\nawait setInstagramPostLike(page, { username: 'user', index: Math.min(10, maxIndex) }, true);","handlingStrategy":"validation","validationCode":"const count = (await readPostSnapshot(page, username, 1, command)).posts.length;\nif (!Number.isInteger(index) || index < 1 || index > count) throw new Error(`--index must be 1..${count}`);","typeGuard":"function isValidIndex(index, posts) { return Number.isInteger(index) && index >= 1 && index <= posts.length; }","tryCatchPattern":"try { await setInstagramPostLike(page, kwargs, true); } catch (e) { if (/Post index .* not found/.test(e.message)) { console.warn(`Index out of range; ${e.message}`); } else throw e; }","preventionTips":["Read the feed snapshot first and clamp the index to posts.length","Re-check the profile after deletions/pinning changes post positions","Remember the index is 1-based","Avoid hardcoding indices across sessions"],"tags":["instagram","user-input","bounds-check"],"backgroundTag":"index-out-of-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}