{"record":{"id":"e2a8f5bdbc5cee7a","repo":"jackwener/OpenCLI","slug":"label-e2a8f5","errorCode":null,"errorMessage":"${label}","messagePattern":"\\$\\{label\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/user-id.js","lineNumber":13,"sourceCode":"/**\n * In-page snippet that resolves `username` to a numeric user id in `userId`.\n *\n * `web_profile_info` answers HTTP 400 for business and professional accounts,\n * so the commands that need an id fall back to feed-by-username. Its root\n * `user.pk` is the profile owner; `items[0].user.pk` can be a pinned collab\n * author. Callers must already have `username` and `opts` in scope.\n */\nexport function buildResolveInstagramUserIdJs() {\n    return `\n  function normalizeInstagramUserId(value, label) {\n    const id = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');\n    if (!/^\\\\d+$/.test(id)) throw new Error(label);\n    return id;\n  }\n  async function readInstagramJson(response, label) {\n    try {\n      return await response.json();\n    } catch {\n      throw new Error(label + ' returned invalid JSON');\n    }\n  }\n  function throwInstagramHttpError(response, label, username) {\n    if (response.status === 404) throw new Error('User not found: ' + username);\n    if (response.status === 401 || response.status === 403) {\n      throw new Error('HTTP ' + response.status + ' - make sure you are logged in to Instagram');\n    }\n    throw new Error(label + ' failed: HTTP ' + response.status);\n  }\n  const r1 = await fetch('https://www.instagram.com/api/v1/users/web_profile_info/?username=' + encodeURIComponent(username), opts);\n  if (r1.status === 404) throw new Error('User not found: ' + username);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/user-id.js#L1-L31","documentation":"Inside the in-page resolver script from buildResolveInstagramUserIdJs, normalizeInstagramUserId validates that a value is a numeric-string id. If it is not (empty, undefined, or non-numeric), it throws new Error(label) — so the thrown message IS the caller's label, e.g. 'Instagram web_profile_info returned no valid user id for: someuser'. It means Instagram's response did not contain a usable numeric user id at the expected path (data.user.id or user.pk).","triggerScenarios":"normalizeInstagramUserId receives a non-numeric value: web_profile_info returned ok but data.user.id was missing/non-numeric, or the feed-by-username fallback's user.pk was missing — the label then surfaces verbatim as the error message.","commonSituations":"Private/restricted profile where data.user is null; mistyped username yielding a degraded 200 response; Instagram A/B response shape changes; rate-limited 200 responses lacking user data.","solutions":["Verify the username is correct and the profile is public/accessible while logged in.","Log the raw web_profile_info response to see why data.user.id is absent.","Ensure the 400-response business-account fallback path (feed-by-username) returns a valid user.pk.","Retry later if Instagram is returning degraded 200 responses (rate limiting).","Update the parsing paths if Instagram changed its response schema."],"exampleFix":"// before\nconst userId = await page.evaluate(buildResolveInstagramUserIdJs());\n// after\nlet userId;\ntry { userId = await page.evaluate(buildResolveInstagramUserIdJs()); }\ncatch (e) {\n  if (String(e.message).includes('no valid user id')) throw new Error('Profile unavailable or private: ' + username);\n  throw e;\n}","handlingStrategy":"validation","validationCode":"// Before resolving, confirm the username is a clean handle\nif (!/^[A-Za-z0-9._]{1,30}$/.test(username)) throw new Error('Invalid Instagram username: ' + username);","typeGuard":"function isNumericUserId(value) {\n  const s = typeof value === 'number' ? String(value) : (typeof value === 'string' ? value.trim() : '');\n  return /^\\d+$/.test(s);\n}","tryCatchPattern":"try {\n  const userId = await page.evaluate(buildResolveInstagramUserIdJs());\n  return userId;\n} catch (e) {\n  if (String(e.message).includes('no valid user id')) throw new Error('Profile unavailable/private: ' + username);\n  throw e;\n}","preventionTips":["Validate username format before resolving.","Confirm the profile is public and accessible in a logged-in browser.","Cache resolved numeric ids to reduce API dependence.","Log raw payloads to handle Instagram response-shape drift."],"tags":["instagram","user-id","validation","response-parsing"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}