{"record":{"id":"881063a0075b93e0","repo":"jackwener/OpenCLI","slug":"index-must-be-a-positive-integer","errorCode":null,"errorMessage":"--index must be a positive integer","messagePattern":"--index must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/post-like.js","lineNumber":182,"sourceCode":"    }\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) {\n        throw new CommandExecutionError(\n            `Could not find the like control on ${post.code}`,\n            'Open the post in the browser and check whether Instagram is asking you to log in, or set the interface language to English.',","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/post-like.js#L164-L200","documentation":"setInstagramPostLike requires --index to be an integer >= 1 (1-based position in the profile's recent posts). This ArgumentError fires when index is missing, not an integer (e.g. a string '2' or float 1.5), or is less than 1, because such a value can never address a valid post.","triggerScenarios":"Omitting --index; passing --index 0 or a negative number; passing a non-numeric or string value from shell wrappers that don't coerce types; float values from JSON configs.","commonSituations":"Thinking the index is 0-based and passing 0; shell scripts interpolating unquoted/empty variables; YAML/JSON configs storing the index as a string.","solutions":["Pass --index as a positive integer (1 = most recent post)","Coerce and validate in wrappers: Number.isInteger(Number.parseInt(v, 10)) && v >= 1","Remember the index is 1-based, not 0-based"],"exampleFix":"// before\nawait setInstagramPostLike(page, { username: 'user', index: 0 }, true);\n// after\nawait setInstagramPostLike(page, { username: 'user', index: 1 }, true);","handlingStrategy":"validation","validationCode":"const idx = Number.parseInt(kwargs.index, 10);\nif (!Number.isInteger(idx) || idx < 1) throw new Error('--index must be a positive integer (1-based)');","typeGuard":"function isValidIndexArg(v) { return Number.isInteger(v) && v >= 1; }","tryCatchPattern":"try { await setInstagramPostLike(page, kwargs, true); } catch (e) { if (e instanceof ArgumentError && /--index/.test(e.message)) { console.error(`Bad --index: ${JSON.stringify(kwargs.index)}; pass an integer >= 1`); } else throw e; }","preventionTips":["Remember the index is 1-based (1 = most recent post)","Coerce string flags to integers in shell wrappers","Reject index 0 early — it is never valid","Document the flag requirement in your automation scripts"],"tags":["validation","user-input","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}