jackwener/OpenCLI · error · AuthRequiredError

reddit.com

Error message

reddit.com

What it means

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.

Source

Thrown at clis/reddit/whoami.js:46

        if (res.status === 401 || res.status === 403) {
          return { kind: 'auth', detail: 'Reddit /api/me.json returned HTTP ' + res.status };
        }
        if (!res.ok) {
          return { kind: 'http', httpStatus: res.status, where: '/api/me.json' };
        }
        const d = await res.json();
        const me = d?.data;
        if (!me?.name) {
          return { kind: 'auth', detail: 'Not logged in to reddit.com (no identity in /api/me.json)' };
        }
        return { kind: 'ok', identity: me };
      } 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(`whoami failed: ${result.detail}`);
        }
        if (result?.kind !== 'ok') {
            throw new CommandExecutionError(`Unexpected result from reddit whoami: ${JSON.stringify(result)}`);
        }

        const u = result.identity;
        const created = u.created_utc
            ? new Date(u.created_utc * 1000).toISOString().split('T')[0]
            : null;
        const linkKarma = typeof u.link_karma === 'number' ? u.link_karma : null;
        const commentKarma = typeof u.comment_karma === 'number' ? u.comment_karma : null;
        const totalKarma = typeof u.total_karma === 'number'

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to reddit.com in the attached Chrome/Chromium, then rerun `reddit whoami` to verify the session.
  2. Use whoami as a preflight auth check before calling other reddit commands.
  3. Catch AuthRequiredError and route to an interactive login flow.
  4. Confirm the correct browser profile is connected if you believe you are logged in.

Example fix

// before
await run(['reddit', 'whoami']); // throws when logged out
// after
import { AuthRequiredError } from '@jackwener/opencli/errors';
async function ensureRedditAuth() {
  try { await run(['reddit', 'whoami']); }
  catch (e) {
    if (e instanceof AuthRequiredError) {
      await interactiveLogin('https://www.reddit.com/login');
      await run(['reddit', 'whoami']);
      return;
    }
    throw e;
  }
}
Defensive patterns

Strategy: try-catch

Type guard

function isAuthRequiredError(e) { return e instanceof AuthRequiredError; }

Try / catch

try {
  const me = await run(['reddit', 'whoami']);
} catch (e) {
  if (e instanceof AuthRequiredError && e.domain === 'reddit.com') {
    await interactiveLogin('https://www.reddit.com/login');
    return await run(['reddit', 'whoami']);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `reddit whoami` without a valid Reddit session: in-page fetch of /api/me.json returns an unauthenticated response, converted at whoami.js:46.

Common situations: Session cookies expired; never logged in on the automation profile; Reddit logged the account out; switching profiles and losing the session.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/1a28871fc5aa4185. Report an issue: GitHub.