jackwener/OpenCLI · error · ArgumentError

username is required

Error message

username is required

What it means

setInstagramPostLike validates its kwargs before doing any browser work and throws ArgumentError when kwargs.username is missing or whitespace-only. The library requires a concrete profile username because all subsequent steps (feed read, post selection) are keyed by it.

Source

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

            `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.',
        );
    }
    return confirmed;
}

export async function setInstagramPostLike(page, kwargs, shouldLike) {
    const username = String(kwargs.username || '').trim();
    const index = kwargs.index;
    const command = shouldLike ? 'instagram like' : 'instagram unlike';
    if (!username) {
        throw new ArgumentError('username is required');
    }
    if (!Number.isInteger(index) || index < 1) {
        throw new ArgumentError('--index must be a positive integer', 'e.g. --index 2 for the second most recent post');
    }

    const snapshot = await readPostSnapshot(page, username, index, command);
    const post = pickPost(snapshot, username, index, command);
    const label = post.caption || `(post #${index})`;
    const settled = [{ status: shouldLike ? 'Already liked' : 'Already unliked', user: username, post: label }];
    if (post.liked === shouldLike) return settled;

    await page.goto(`https://www.instagram.com/p/${post.code}/`, { settleMs: 2000 });
    let click = null;
    for (let attempt = 0; attempt < 5 && !click?.found; attempt += 1) {
        if (attempt > 0) await page.sleep(1);
        click = unwrapEvaluateResult(await page.evaluate(buildToggleLikeJs(shouldLike)));
    }
    if (!click?.found) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass --username <name> (or kwargs.username) with a non-empty trimmed value
  2. Add shell/CI checks that fail fast when required flags are empty
  3. In wrappers, validate kwargs.username with String(x||'').trim() before invoking

Example fix

// before
await setInstagramPostLike(page, { index: 1 }, true);
// after
await setInstagramPostLike(page, { username: 'target_user', index: 1 }, true);
Defensive patterns

Strategy: validation

Validate before calling

const username = String(kwargs.username || '').trim();
if (!username) throw new Error('username is required before calling setInstagramPostLike');

Type guard

function hasUsername(k) { return typeof k === 'object' && k !== null && typeof k.username === 'string' && k.username.trim().length > 0; }

Try / catch

try { await setInstagramPostLike(page, kwargs, true); } catch (e) { if (e instanceof ArgumentError && /username is required/.test(e.message)) { console.error('Pass --username <name>'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Calling instagram like/unlike without --username, with --username "" , or passing the flag with only spaces; programmatically calling setInstagramPostLike with an object lacking the username key.

Common situations: Scripting wrappers that build kwargs dynamically and drop empty values; CLI invocations missing the required flag; copy-paste errors where the username ended up in the wrong flag.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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