jackwener/OpenCLI · error · AuthRequiredError
reddit.com
reddit.com
Error message
reddit.com: ${result.detail} What it means
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.
Source
Thrown at clis/reddit/home.js:109
if (res.status === 401 || res.status === 403) {
return { kind: 'auth', detail: 'Reddit /best.json returned HTTP ' + res.status };
}
if (!res.ok) {
return { kind: 'http', httpStatus: res.status, where: '/best.json' };
}
const j = await res.json();
const entries = j?.data?.children;
if (!Array.isArray(entries)) {
return { kind: 'http', httpStatus: 200, where: '/best.json (no data.children array)' };
}
return { kind: 'ok', entries };
} catch (e) {
return { kind: 'exception', detail: String(e && e.message || e) };
}
})()`);
if (result?.kind === 'auth') {
throw new AuthRequiredError('reddit.com', result.detail);
}
if (result?.kind === 'http') {
throw new CommandExecutionError(`HTTP ${result.httpStatus} from ${result.where}`);
}
if (result?.kind === 'exception') {
throw new CommandExecutionError(`home failed: ${result.detail}`);
}
if (result?.kind !== 'ok') {
throw new CommandExecutionError(`Unexpected result from reddit home: ${JSON.stringify(result)}`);
}
const rows = [];
const entries = result.entries.slice(0, limit);
for (let i = 0; i < entries.length; i++) {
const d = entries[i]?.data;
if (!d || !d.id) continue;
rows.push({
rank: i + 1,View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before: anonymous in CI opencli reddit home --limit 10 # AuthRequiredError: Not logged in to reddit.com // after: restore persisted profile / login opencli reddit login && opencli reddit home --limit 10
Defensive patterns
Strategy: try-catch
Validate before calling
// confirm logged-in identity before running home
const me = await page.evaluate(`fetch('/api/me.json',{credentials:'include'}).then(r=>r.json())`);
if (!me?.data?.name) await runRedditLogin(page); Type guard
function isLoggedIn(me) {
return typeof me?.data?.name === 'string' && me.data.name.length > 0;
} Try / catch
try {
const feed = await opencli.reddit.home({ limit: 10 });
} catch (e) {
if (e instanceof AuthRequiredError && e.code === 'reddit.com') {
await opencli.reddit.login();
return opencli.reddit.home({ limit: 10 });
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 请先在共享 Chrome 完成 1688 登录/验证,再重试(${action})
- Bilibili ${label} API requires login or permission: ${messag
- bilibili.com
- ${probe.detail}
- result.detail (auth required from Claude probe)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/dab6ed09bc8069d1.
Report an issue: GitHub.