{"record":{"id":"fa45d6d300068119","repo":"jackwener/OpenCLI","slug":"unexpected-reddit-probe-json-stringify-result","errorCode":null,"errorMessage":"Unexpected Reddit probe: ${JSON.stringify(result)}","messagePattern":"Unexpected Reddit probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/auth.js","lineNumber":35,"sourceCode":"      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});\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/auth.js#L17-L53","documentation":"CommandExecutionError thrown as a catch-all in verifyRedditIdentity when the probe result is neither ok, auth, http, nor exception — i.e. the in-page script returned an unexpected shape (or null/undefined). This guards against unanticipated probe payloads and bug fixes in the page script being silently ignored.","triggerScenarios":"The page.evaluate result lacks the expected `kind`/`ok` fields — e.g. the evaluate returned undefined because the page context was destroyed mid-script, or a wrapper/driver serialized the result differently than expected.","commonSituations":"Automation driver version mismatch changing evaluate serialization; page crashed/navigated during evaluation returning null; modifications to the probe script returning an undocumented shape.","solutions":["Re-run once to rule out a transient destroyed-context evaluate.","Update the CLI/automation driver pair to compatible versions so evaluate results serialize as expected.","Inspect the JSON in the message — it shows the actual unexpected result and narrows the cause.","If reproducible, capture browser console/page state at evaluate time to see why the probe returned a malformed value."],"exampleFix":"// before: page torn down during evaluate\nawait page.close(); const r = await verifyRedditIdentity(page);\n// after: verify before closing\nconst r = await verifyRedditIdentity(page); await page.close();","handlingStrategy":"type-guard","validationCode":"// keep the page open and idle while probing\nif (page.isClosed?.()) throw new Error('page already closed');","typeGuard":"function isProbeResult(r) {\n  return !!r && typeof r === 'object' && typeof r.kind === 'string' &&\n    ['ok','auth','http','exception'].includes(r.kind);\n}","tryCatchPattern":"try {\n  const me = await opencli.reddit.whoami();\n} catch (e) {\n  if (/Unexpected Reddit probe/.test(e.message)) {\n    // malformed probe result: check driver versions / page lifecycle\n    console.error(e.message);\n  }\n  throw e;\n}","preventionTips":["Keep automation driver and CLI versions compatible (evaluate serialization).","Never tear down the page concurrently with evaluate calls.","Log unexpected probe payloads for debugging.","Validate that evaluate returns an object before further processing in custom wrappers."],"tags":["reddit","unexpected-state","browser"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}