{"record":{"id":"dab6ed09bc8069d1","repo":"jackwener/OpenCLI","slug":"reddit-com-dab6ed","errorCode":"reddit.com","errorMessage":"reddit.com: ${result.detail}","messagePattern":"reddit\\.com: (.+?)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/reddit/home.js","lineNumber":109,"sourceCode":"        if (res.status === 401 || res.status === 403) {\n          return { kind: 'auth', detail: 'Reddit /best.json returned HTTP ' + res.status };\n        }\n        if (!res.ok) {\n          return { kind: 'http', httpStatus: res.status, where: '/best.json' };\n        }\n        const j = await res.json();\n        const entries = j?.data?.children;\n        if (!Array.isArray(entries)) {\n          return { kind: 'http', httpStatus: 200, where: '/best.json (no data.children array)' };\n        }\n        return { kind: 'ok', entries };\n      } catch (e) {\n        return { kind: 'exception', detail: String(e && e.message || e) };\n      }\n    })()`);\n\n        if (result?.kind === 'auth') {\n            throw new AuthRequiredError('reddit.com', result.detail);\n        }\n        if (result?.kind === 'http') {\n            throw new CommandExecutionError(`HTTP ${result.httpStatus} from ${result.where}`);\n        }\n        if (result?.kind === 'exception') {\n            throw new CommandExecutionError(`home failed: ${result.detail}`);\n        }\n        if (result?.kind !== 'ok') {\n            throw new CommandExecutionError(`Unexpected result from reddit home: ${JSON.stringify(result)}`);\n        }\n\n        const rows = [];\n        const entries = result.entries.slice(0, limit);\n        for (let i = 0; i < entries.length; i++) {\n            const d = entries[i]?.data;\n            if (!d || !d.id) continue;\n            rows.push({\n                rank: i + 1,","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/home.js#L91-L127","documentation":"AuthRequiredError thrown by `reddit home` when the in-page probe reports kind==='auth': /api/me.json or /best.json returned 401/403, or /api/me.json returned 200 with no data.name. `home` is the personalized Best feed and deliberately refuses to return the anonymous listing, so any indication of a logged-out or rejected session surfaces as auth-required for reddit.com.","triggerScenarios":"Running `reddit home` with no login or a stale cookie session: meRes 401/403, or 200 with me.data.name missing; also /best.json returning 401/403 despite a technically-present cookie.","commonSituations":"Expired reddit_session after weeks away; Reddit logged the session out remotely; using a fresh CI container with no persisted login; cookie present but Reddit flags it anonymous after a block/challenge.","solutions":["Run the reddit login flow to establish a fresh session, then re-run home.","Clear old Reddit cookies in the automation profile before re-login to avoid stale-session ambiguity.","Persist the browser profile between runs (CI: cache the profile directory) so login survives.","If 401/403 persists right after login, check whether Reddit is serving a block/challenge page for your IP and resolve that first."],"exampleFix":"// before: anonymous in CI\nopencli reddit home --limit 10  # AuthRequiredError: Not logged in to reddit.com\n// after: restore persisted profile / login\nopencli reddit login && opencli reddit home --limit 10","handlingStrategy":"try-catch","validationCode":"// confirm logged-in identity before running home\nconst me = await page.evaluate(`fetch('/api/me.json',{credentials:'include'}).then(r=>r.json())`);\nif (!me?.data?.name) await runRedditLogin(page);","typeGuard":"function isLoggedIn(me) {\n  return typeof me?.data?.name === 'string' && me.data.name.length > 0;\n}","tryCatchPattern":"try {\n  const feed = 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":["Cache and restore the logged-in browser profile (especially in CI).","Treat a 200-without-identity response as logged out and re-login proactively.","Re-authenticate after long idle periods; reddit_session expires.","Watch for Reddit challenges/blocks that silently downgrade sessions to anonymous."],"tags":["auth","reddit","session-expired","home-feed"],"backgroundTag":"session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}