{"record":{"id":"96c43091094911b0","repo":"jackwener/OpenCLI","slug":"username-is-required-96c430","errorCode":null,"errorMessage":"username is required","messagePattern":"username is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/post-like.js","lineNumber":179,"sourceCode":"            `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.',\n        );\n    }\n    return confirmed;\n}\n\nexport async function setInstagramPostLike(page, kwargs, shouldLike) {\n    const username = String(kwargs.username || '').trim();\n    const index = kwargs.index;\n    const command = shouldLike ? 'instagram like' : 'instagram unlike';\n    if (!username) {\n        throw new ArgumentError('username is required');\n    }\n    if (!Number.isInteger(index) || index < 1) {\n        throw new ArgumentError('--index must be a positive integer', 'e.g. --index 2 for the second most recent post');\n    }\n\n    const snapshot = await readPostSnapshot(page, username, index, command);\n    const post = pickPost(snapshot, username, index, command);\n    const label = post.caption || `(post #${index})`;\n    const settled = [{ status: shouldLike ? 'Already liked' : 'Already unliked', user: username, post: label }];\n    if (post.liked === shouldLike) return settled;\n\n    await page.goto(`https://www.instagram.com/p/${post.code}/`, { settleMs: 2000 });\n    let click = null;\n    for (let attempt = 0; attempt < 5 && !click?.found; attempt += 1) {\n        if (attempt > 0) await page.sleep(1);\n        click = unwrapEvaluateResult(await page.evaluate(buildToggleLikeJs(shouldLike)));\n    }\n    if (!click?.found) {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/post-like.js#L161-L197","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass --username <name> (or kwargs.username) with a non-empty trimmed value","Add shell/CI checks that fail fast when required flags are empty","In wrappers, validate kwargs.username with String(x||'').trim() before invoking"],"exampleFix":"// before\nawait setInstagramPostLike(page, { index: 1 }, true);\n// after\nawait setInstagramPostLike(page, { username: 'target_user', index: 1 }, true);","handlingStrategy":"validation","validationCode":"const username = String(kwargs.username || '').trim();\nif (!username) throw new Error('username is required before calling setInstagramPostLike');","typeGuard":"function hasUsername(k) { return typeof k === 'object' && k !== null && typeof k.username === 'string' && k.username.trim().length > 0; }","tryCatchPattern":"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; }","preventionTips":["Always pass --username in CLI invocations","Validate kwargs in wrapper scripts before calling the API","Quote shell variables so empty values are still passed predictably","Add CI checks that fail fast on empty required flags"],"tags":["validation","user-input","argument-error"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}