{"record":{"id":"4a7f88e761c8d767","repo":"jackwener/OpenCLI","slug":"user-not-found-username-or-http-r1-stat","errorCode":null,"errorMessage":"User not found: ' + username (or 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram')","messagePattern":"User not found: ' \\+ username \\(or 'HTTP ' \\+ r1\\.status \\+ ' - make sure you are logged in to Instagram'\\)","errorType":"http","errorClass":"Error","httpStatus":404,"severity":"error","filePath":"clis/instagram/comment.js","lineNumber":54,"sourceCode":"    if (!feed || typeof feed !== 'object' || !Array.isArray(feed.items)) {\n      throw new Error(label + ' returned malformed items payload');\n    }\n    if (idx >= feed.items.length) throw new Error('Post index ' + (idx + 1) + ' not found');\n    const post = feed.items[idx];\n    const pkRaw = post?.pk ?? post?.id;\n    const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');\n    if (!/^\\\\d+$/.test(pk)) throw new Error(label + ' returned malformed post row');\n    return { pk };\n  }\n  function assertOkStatus(payload, label) {\n    if (!payload || typeof payload !== 'object' || payload.status !== 'ok') {\n      throw new Error(label + ' returned no success evidence');\n    }\n  }\n\n  // web_profile_info answers HTTP 400 for business accounts; feed-by-username needs no user id. See #2234.\n  const r1 = await fetch('https://www.instagram.com/api/v1/feed/user/' + encodeURIComponent(username) + '/username/?count=' + (idx + 1), opts);\n  if (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');\n  const { pk } = getPostFromFeed(await readInstagramJson(r1, 'Instagram feed-by-username'), 'Instagram feed-by-username');\n\n  const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';\n  const r2 = await fetch('https://www.instagram.com/api/v1/web/comments/' + pk + '/add/', {\n    method: 'POST', credentials: 'include',\n    headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },\n    body: 'comment_text=' + encodeURIComponent(commentText),\n  });\n  if (!r2.ok) throw new Error('Failed to comment: HTTP ' + r2.status);\n  assertOkStatus(await readInstagramJson(r2, 'Instagram comment'), 'Instagram comment');\n  return [{ status: 'Commented', user: username, text: commentText }];\n})()\n` },\n    ],\n});\n","sourceCodeStart":36,"sourceCodeEnd":70,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/comment.js#L36-L70","documentation":"The feed-by-username pre-fetch fails the res.ok check: a 404 is mapped to 'User not found: <username>' while any other non-ok status yields 'HTTP <status> - make sure you are logged in to Instagram'. The comment flow aborts before locating the post.","triggerScenarios":"Username does not exist (404); session cookies expired or missing so Instagram returns 302/401/403; rate limiting (429); the count parameter request rejected by IG.","commonSituations":"Typo in --username or the account was renamed/deleted; cookies stale after password change or logout elsewhere; running many requests in a row triggering IG throttling; business accounts where older endpoints 400 (the CLI already switched to feed-by-username, see #2234).","solutions":["Verify the username is correct and the account exists/public","Refresh Instagram login cookies before running; the 'not logged in' branch almost always means stale cookies","Add backoff/retry on 429 and reduce request frequency","Handle 404 as a terminal skip in automation instead of retrying"],"exampleFix":"// before\nif (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');\n// after\nif (!r1.ok) {\n  if (r1.status === 404) throw new Error('User not found: ' + username);\n  if (r1.status === 429) throw new Error('Rate limited by Instagram - wait and retry');\n  throw new Error('HTTP ' + r1.status + ' - make sure you are logged in to Instagram');\n}","handlingStrategy":"validation","validationCode":"if (!username || typeof username !== 'string' || /[^A-Za-z0-9._]/.test(username)) {\n  throw new Error('Invalid username: ' + username);\n}\n// ensure cookies are loaded before running\nif (!cookies.includes('sessionid')) throw new Error('Not logged in - missing session cookie');","typeGuard":"function isValidUsername(u) {\n  return typeof u === 'string' && /^[A-Za-z0-9._]{1,30}$/.test(u);\n}","tryCatchPattern":"try {\n  await runCommentPipeline(args);\n} catch (e) {\n  if (/User not found/.test(e.message)) {\n    console.warn('Skip: account does not exist');\n  } else if (/HTTP \\d+/.test(e.message)) {\n    console.error('Refresh Instagram login cookies and retry');\n  } else throw e;\n}","preventionTips":["Validate usernames before invoking","Keep sessionid/csrftoken cookies fresh","Throttle requests to avoid 429s","Handle 404 as terminal skip in bulk jobs"],"tags":["instagram","http-status","auth","user-not-found"],"backgroundTag":"http-401-unauthorized","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}