{"record":{"id":"a45d20de169d46ef","repo":"jackwener/OpenCLI","slug":"unexpected-instagram-probe-json-stringify-resul","errorCode":null,"errorMessage":"Unexpected Instagram probe: ${JSON.stringify(result)}","messagePattern":"Unexpected Instagram probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/auth.js","lineNumber":40,"sourceCode":"      });\n      if (r.status === 401 || r.status === 403) {\n        return { kind: 'auth', detail: 'Instagram /users/info HTTP ' + r.status };\n      }\n      if (!r.ok) return { kind: 'http', httpStatus: r.status };\n      const d = await r.json();\n      const user = d?.user;\n      if (!user || !user.pk) {\n        return { kind: 'auth', detail: 'Instagram /users/info returned no pk — session likely expired' };\n      }\n      return { ok: true, user_id: String(user.pk), username: String(user.username || ''), full_name: String(user.full_name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('www.instagram.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from Instagram /users/info`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Instagram whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Instagram probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, username: result.username, full_name: result.full_name };\n}\n\nregisterSiteAuthCommands({\n  site: 'instagram',\n  domain: 'instagram.com',\n  loginUrl: 'https://www.instagram.com/accounts/login/',\n  columns: ['user_id', 'username', 'full_name'],\n  quickCheck: hasInstagramSessionCookie,\n  verify: verifyInstagramIdentity,\n  poll: async (page) => {\n    if (!await hasInstagramSessionCookie(page)) {\n      throw new AuthRequiredError('www.instagram.com', 'Waiting for Instagram sessionid cookie');\n    }\n    return verifyInstagramIdentity(page);\n  },\n});\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/auth.js#L22-L58","documentation":"A defensive CommandExecutionError thrown when the whoami probe returns a result that is neither ok, nor one of the known kinds ('auth', 'http', 'exception'), or is null/undefined. The library throws this to catch contract violations — i.e. the page.evaluate returned something unexpected, so the result cannot be interpreted safely. It is a bug-catcher rather than an expected runtime condition.","triggerScenarios":"page.evaluate in verifyInstagramIdentity resolves to null/undefined (page navigation destroyed the execution context, evaluate failed silently) or returns an object with an unrecognized `kind` — e.g. an older probe script or a wrapper that altered the return shape.","commonSituations":"Page navigated away or was closed while the probe was running; a browser automation layer returning undefined from evaluate; mixing CLI versions where the probe script and the dispatcher disagree; a site-auth wrapper modifying probe results.","solutions":["Re-run the command — a transient page navigation/context destruction often resolves on retry","Make sure the page stays open on instagram.com until the command finishes (don't close or navigate the browser mid-command)","Ensure CLI and its site-auth helpers are the same version; reinstall/update the CLI if mixed","If reproducible, report it — the probe returned a shape the code does not recognize"],"exampleFix":"// before: closing the browser mid-command causes evaluate to yield undefined\n// after: await the command before closing\nawait opencli instagram whoami;\nawait browser.close();","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"function isKnownProbeResult(r) {\n  return r != null && typeof r === 'object' &&\n    ['auth', 'http', 'exception'].includes(r.kind) || r?.ok === true;\n}\n// treat anything failing this guard as the 'Unexpected Instagram probe' case","tryCatchPattern":"try {\n  await instagramWhoami();\n} catch (e) {\n  if (e.message.startsWith('Unexpected Instagram probe:')) {\n    // evaluate returned null/unknown shape — usually a destroyed page context\n    await reopenInstagramPage();\n    return instagramWhoami();\n  }\n  throw e;\n}","preventionTips":["Don't navigate or close the page while a command is executing","Run a single CLI version consistently; mixed versions can change probe result shapes","If wrapping site-auth flows, don't transform the probe result object","Retry once — a transient context destruction commonly causes an undefined evaluate result"],"tags":["instagram","unexpected-state","defensive","page-context"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}