{"record":{"id":"d7e35a22774b236c","repo":"jackwener/OpenCLI","slug":"user-not-found-username-d7e35a","errorCode":null,"errorMessage":"User not found: ' + username","messagePattern":"User not found: ' \\+ username","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"clis/instagram/unsave.js","lineNumber":53,"sourceCode":"      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    const caption = typeof post?.caption?.text === 'string' ? post.caption.text.substring(0, 60) : '';\n    return { pk, caption };\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, caption } = 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/save/' + pk + '/unsave/', {\n    method: 'POST', credentials: 'include',\n    headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },\n  });\n  if (!r2.ok) throw new Error('Failed to unsave: HTTP ' + r2.status);\n  assertOkStatus(await readInstagramJson(r2, 'Instagram unsave'), 'Instagram unsave');\n  return [{ status: 'Unsaved', user: username, post: caption || '(post #' + (idx+1) + ')' }];\n})()\n` },\n    ],\n});\n","sourceCodeStart":35,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/unsave.js#L35-L68","documentation":"The feed-by-username endpoint answered HTTP 404, meaning no Instagram account exists for the given username. The CLI translates the 404 into this explicit message. The username string is echoed verbatim into the error.","triggerScenarios":"Calling unsave (or user) with a username that is misspelled, deactivated, deleted, or renamed; 404 status from /api/v1/feed/user/{username}/username/.","commonSituations":"Typos or wrong casing assumptions; account was deleted or banned; user changed their handle; scraping an account that blocked you (may surface differently).","solutions":["Verify the exact current username on instagram.com and correct the argument.","Handle renamed accounts by re-looking-up the profile.","Skip/remove the target if the account was deleted or banned."],"exampleFix":"// before\nnpx cli instagram unsave --username jonh_doe --index 1\n// after\nnpx cli instagram unsave --username john_doe --index 1  # corrected spelling","handlingStrategy":"validation","validationCode":"const exists = await profileExists(username);\nif (!exists) throw new Error(`User not found: ${username}`);","typeGuard":null,"tryCatchPattern":"try {\n  await cli.unsave(user, index);\n} catch (e) {\n  if (e.message.startsWith('User not found')) {\n    console.error(`Skip: ${user} does not exist (deleted, renamed, or banned).`);\n  } else throw e;\n}","preventionTips":["Copy usernames exactly from instagram.com","Handle renamed accounts via stored user IDs where possible","Periodically validate that target accounts still exist"],"tags":["instagram","http-404","not-found","arguments"],"backgroundTag":"resource-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}