{"record":{"id":"1a28871fc5aa4185","repo":"jackwener/OpenCLI","slug":"reddit-com-1a2887","errorCode":null,"errorMessage":"reddit.com","messagePattern":"reddit\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/reddit/whoami.js","lineNumber":46,"sourceCode":"        if (res.status === 401 || res.status === 403) {\n          return { kind: 'auth', detail: 'Reddit /api/me.json returned HTTP ' + res.status };\n        }\n        if (!res.ok) {\n          return { kind: 'http', httpStatus: res.status, where: '/api/me.json' };\n        }\n        const d = await res.json();\n        const me = d?.data;\n        if (!me?.name) {\n          return { kind: 'auth', detail: 'Not logged in to reddit.com (no identity in /api/me.json)' };\n        }\n        return { kind: 'ok', identity: me };\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(`whoami failed: ${result.detail}`);\n        }\n        if (result?.kind !== 'ok') {\n            throw new CommandExecutionError(`Unexpected result from reddit whoami: ${JSON.stringify(result)}`);\n        }\n\n        const u = result.identity;\n        const created = u.created_utc\n            ? new Date(u.created_utc * 1000).toISOString().split('T')[0]\n            : null;\n        const linkKarma = typeof u.link_karma === 'number' ? u.link_karma : null;\n        const commentKarma = typeof u.comment_karma === 'number' ? u.comment_karma : null;\n        const totalKarma = typeof u.total_karma === 'number'","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/whoami.js#L28-L64","documentation":"clis/reddit/whoami.js throws AuthRequiredError('reddit.com', result.detail) when the browser probe reports kind 'auth', meaning reddit.com does not recognize the current session when asking who the logged-in user is. The typed error carries the domain and detail so tooling can react specifically to missing Reddit authentication. Hint text directs the user to log in via Chrome/Chromium.","triggerScenarios":"Running `reddit whoami` without a valid Reddit session: in-page fetch of /api/me.json returns an unauthenticated response, converted at whoami.js:46.","commonSituations":"Session cookies expired; never logged in on the automation profile; Reddit logged the account out; switching profiles and losing the session.","solutions":["Log in to reddit.com in the attached Chrome/Chromium, then rerun `reddit whoami` to verify the session.","Use whoami as a preflight auth check before calling other reddit commands.","Catch AuthRequiredError and route to an interactive login flow.","Confirm the correct browser profile is connected if you believe you are logged in."],"exampleFix":"// before\nawait run(['reddit', 'whoami']); // throws when logged out\n// after\nimport { AuthRequiredError } from '@jackwener/opencli/errors';\nasync function ensureRedditAuth() {\n  try { await run(['reddit', 'whoami']); }\n  catch (e) {\n    if (e instanceof AuthRequiredError) {\n      await interactiveLogin('https://www.reddit.com/login');\n      await run(['reddit', 'whoami']);\n      return;\n    }\n    throw e;\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAuthRequiredError(e) { return e instanceof AuthRequiredError; }","tryCatchPattern":"try {\n  const me = await run(['reddit', 'whoami']);\n} catch (e) {\n  if (e instanceof AuthRequiredError && e.domain === 'reddit.com') {\n    await interactiveLogin('https://www.reddit.com/login');\n    return await run(['reddit', 'whoami']);\n  }\n  throw e;\n}","preventionTips":["Use whoami as a cheap preflight before other reddit commands","Keep the attached profile logged in and detect expiry early","Catch AuthRequiredError specifically rather than generic errors","Route auth failures to a single login-recovery flow in your tooling"],"tags":["authentication","reddit","whoami"],"backgroundTag":"site-login-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}