{"record":{"id":"bd4c0a41b833e242","repo":"jackwener/OpenCLI","slug":"reddit-whoami-failed-result-detail","errorCode":null,"errorMessage":"Reddit whoami failed: ${result.detail}","messagePattern":"Reddit whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/auth.js","lineNumber":34,"sourceCode":"    try {\n      const res = await fetch('/api/me.json', { credentials: 'include', headers: { 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Reddit /api/me.json HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      const data = d && d.data;\n      if (!data || !data.name) {\n        return { kind: 'auth', detail: 'Reddit /api/me.json 200 but no data.name — anonymous' };\n      }\n      return { ok: true, username: String(data.name), id: String(data.id || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('reddit.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/me.json`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Reddit whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Reddit probe: ${JSON.stringify(result)}`);\n  return { username: result.username, id: result.id };\n}\n\nregisterSiteAuthCommands({\n  site: 'reddit',\n  domain: 'reddit.com',\n  loginUrl: 'https://www.reddit.com/login',\n  columns: ['username', 'id'],\n  quickCheck: hasRedditSessionCookie,\n  verify: verifyRedditIdentity,\n  poll: async (page) => {\n    if (!await hasRedditSessionCookie(page)) {\n      throw new AuthRequiredError('reddit.com', 'Waiting for Reddit reddit_session cookie');\n    }\n    return verifyRedditIdentity(page);\n  },\n});","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/auth.js#L16-L52","documentation":"CommandExecutionError thrown when the in-page IIFE inside verifyRedditIdentity throws and returns {kind:'exception'}. The browser-side fetch/JSON parse of /api/me.json failed, and its message is surfaced here. It is a client-side (in-page) execution failure rather than a documented Reddit status.","triggerScenarios":"The fetch itself rejects inside the page context: network error/TLS failure, page navigated mid-evaluate killing the async fetch, CORS/context issues, or res.json() throwing on a non-JSON body (e.g. an HTML block page).","commonSituations":"Reddit serving a quarantine/block interstitial HTML instead of JSON; flaky network in the automation browser; page.close() or navigation racing the evaluate; corporate MITM proxy breaking TLS.","solutions":["Re-run the command; transient network/navigation races often clear on retry.","Check what the browser actually renders at reddit.com — a block/quarantine page means the JSON parse failed; solve the block first.","Ensure no concurrent navigation or page.close() happens while verifyRedditIdentity is evaluating.","Test network from the automation browser directly; fix proxy/TLS issues if fetch fails at the network layer."],"exampleFix":"// before: evaluate racing a navigation\nawait Promise.all([page.goto('https://www.reddit.com/'), verifyRedditIdentity(page)]);\n// after: sequence the calls\nawait page.goto('https://www.reddit.com/');\nawait verifyRedditIdentity(page);","handlingStrategy":"try-catch","validationCode":"// ensure the page is alive and settled before evaluating\nawait page.goto('https://www.reddit.com/', { waitUntil: 'load' });\nif (page.isClosed?.()) throw new Error('page closed before probe');","typeGuard":null,"tryCatchPattern":"try {\n  const me = await opencli.reddit.whoami();\n} catch (e) {\n  if (/Reddit whoami failed/.test(e.message)) {\n    console.error('In-page probe failed:', e.message); // inspect detail, retry or check network\n  }\n  throw e;\n}","preventionTips":["Don't navigate or close the page while auth probes are in flight.","Retry transient fetch failures once before failing hard.","Check for block/quarantine pages when res.json() fails (HTML body).","Verify TLS/proxy setup in the automation browser if failures are consistent."],"tags":["reddit","browser","fetch","json"],"backgroundTag":"fetch-failed-in-browser","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}