{"record":{"id":"220ec48a618de071","repo":"jackwener/OpenCLI","slug":"reddit-com","errorCode":"reddit.com","errorMessage":"Reddit reddit_session cookie missing","messagePattern":"Reddit reddit_session cookie missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/reddit/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasRedditSessionCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://www.reddit.com' });\n  return cookies.some(c => c.name === 'reddit_session' && c.value);\n}\n\nasync function verifyRedditIdentity(page) {\n  if (!await hasRedditSessionCookie(page)) {\n    throw new AuthRequiredError('reddit.com', 'Reddit reddit_session cookie missing');\n  }\n  await page.goto('https://www.reddit.com/');\n  await page.wait(2);\n  const result = await page.evaluate(`(async () => {\n    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) };","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/auth.js#L1-L29","documentation":"This AuthRequiredError is thrown by verifyRedditIdentity in clis/reddit/auth.js when the browser context has no non-empty `reddit_session` cookie for reddit.com. The library requires that cookie as a precondition before probing /api/me.json, because Reddit's personalized/identity APIs only work for an authenticated session. It signals the user must log in to Reddit in the automation browser.","triggerScenarios":"Calling any registered reddit site-auth command (or `home`, which routes through verifyRedditIdentity) before ever completing a browser login: page.getCookies({url:'https://www.reddit.com'}) returns no `reddit_session` cookie, or one with an empty value.","commonSituations":"Fresh browser profile / first run of the CLI; the user skipped the interactive login step; cookies were cleared or the profile directory was wiped; a corporate proxy or cookie-blocking extension strips Reddit cookies.","solutions":["Run the library's login flow for the reddit site (opens https://www.reddit.com/login) and complete an interactive login so the reddit_session cookie is set.","Verify the browser profile/persisted context directory is the one the CLI actually reuses, so cookies survive restarts.","Manually log in to reddit.com in the automation browser and re-run the command.","Check that no extension/proxy is stripping cookies from https://www.reddit.com."],"exampleFix":"// before (no session)\nopencli reddit home --limit 10\n// after (login first)\nopencli reddit login   # completes browser login, sets reddit_session\nopencli reddit home --limit 10","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.reddit.com' });\nif (!cookies.some(c => c.name === 'reddit_session' && c.value)) {\n  await runRedditLogin(page); // establish session before calling commands\n}","typeGuard":"function hasRedditSession(cookies) {\n  return Array.isArray(cookies) && cookies.some(c => c?.name === 'reddit_session' && typeof c.value === 'string' && c.value.length > 0);\n}","tryCatchPattern":"try {\n  await opencli.reddit.home({ limit: 10 });\n} catch (e) {\n  if (e instanceof AuthRequiredError && e.code === 'reddit.com') {\n    await opencli.reddit.login();\n    return opencli.reddit.home({ limit: 10 });\n  }\n  throw e;\n}","preventionTips":["Always run the site login flow before auth-required commands in fresh environments.","Persist the browser profile directory so cookies survive restarts and CI runs.","Proactively check for the reddit_session cookie before invoking commands.","Never wipe or reset the automation profile without re-logging in afterwards."],"tags":["auth","reddit","cookie","session"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}