jackwener/OpenCLI · warning · EmptyResultError

Post index ${index} not found; ${username} has ${snapshot.po

Error message

Post index ${index} not found; ${username} has ${snapshot.posts.length} recent posts.

What it means

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.

Source

Thrown at clis/instagram/_shared/post-like.js:150

        return {
            code,
            pk,
            caption: typeof item.caption === 'string' ? item.caption : '',
            liked: item.liked,
        };
    });
    return { ownerId, posts };
}

async function readPostSnapshot(page, username, index, command) {
    const feed = unwrapEvaluateResult(await page.evaluate(buildReadPostsJs(username, index)));
    return normalizeFeedSnapshot(feed, command, username);
}

function pickPost(snapshot, username, index, command) {
    const post = snapshot.posts[index - 1];
    if (!post) {
        throw new EmptyResultError(command, snapshot.posts.length === 0
            ? `No visible posts for ${username}; check the username and whether the account is private.`
            : `Post index ${index} not found; ${username} has ${snapshot.posts.length} recent posts.`);
    }
    return post;
}

async function confirmPersistedState(page, username, index, command, expectedPost, shouldLike) {
    const confirmed = pickPost(await readPostSnapshot(page, username, index, command), username, index, command);
    if (confirmed.code !== expectedPost.code || confirmed.pk !== expectedPost.pk) {
        throw new CommandExecutionError(
            `Instagram post feed no longer shows the expected post ${expectedPost.code} at index ${index}`,
            'The profile feed may have re-rendered or changed order; retry after checking the post in the browser.',
        );
    }
    if (confirmed.liked !== shouldLike) {
        throw new CommandExecutionError(
            `Instagram did not persist the ${shouldLike ? 'like' : 'unlike'} on ${expectedPost.code}`,
            'The action may have been rejected. Retry later, or check the post in the browser.',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the listing/read command first to see how many posts exist, then choose a valid --index
  2. Clamp index to snapshot.posts.length in your wrapper before calling the API
  3. Re-check whether pinned/deleted posts changed the visible count since your last run

Example fix

// before: arbitrary index
await setInstagramPostLike(page, { username: 'user', index: 10 }, true);
// after: clamp to available posts
const maxIndex = snapshot.posts.length;
await setInstagramPostLike(page, { username: 'user', index: Math.min(10, maxIndex) }, true);
Defensive patterns

Strategy: validation

Validate before calling

const count = (await readPostSnapshot(page, username, 1, command)).posts.length;
if (!Number.isInteger(index) || index < 1 || index > count) throw new Error(`--index must be 1..${count}`);

Type guard

function isValidIndex(index, posts) { return Number.isInteger(index) && index >= 1 && index <= posts.length; }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/86d0a14d54e8d0de. Report an issue: GitHub.