jackwener/OpenCLI · error · CommandExecutionError

Reddit whoami failed: ${result.detail}

Error message

Reddit whoami failed: ${result.detail}

What it means

CommandExecutionError thrown when the in-page IIFE inside verifyRedditIdentity throws and returns {kind:'exception'}. The browser-side fetch/JSON parse of /api/me.json failed, and its message is surfaced here. It is a client-side (in-page) execution failure rather than a documented Reddit status.

Source

Thrown at clis/reddit/auth.js:34

    try {
      const res = await fetch('/api/me.json', { credentials: 'include', headers: { 'Accept': 'application/json' } });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'Reddit /api/me.json HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      const data = d && d.data;
      if (!data || !data.name) {
        return { kind: 'auth', detail: 'Reddit /api/me.json 200 but no data.name — anonymous' };
      }
      return { ok: true, username: String(data.name), id: String(data.id || '') };
    } 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 /api/me.json`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Reddit whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Reddit probe: ${JSON.stringify(result)}`);
  return { username: result.username, id: result.id };
}

registerSiteAuthCommands({
  site: 'reddit',
  domain: 'reddit.com',
  loginUrl: 'https://www.reddit.com/login',
  columns: ['username', 'id'],
  quickCheck: hasRedditSessionCookie,
  verify: verifyRedditIdentity,
  poll: async (page) => {
    if (!await hasRedditSessionCookie(page)) {
      throw new AuthRequiredError('reddit.com', 'Waiting for Reddit reddit_session cookie');
    }
    return verifyRedditIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command; transient network/navigation races often clear on retry.
  2. Check what the browser actually renders at reddit.com — a block/quarantine page means the JSON parse failed; solve the block first.
  3. Ensure no concurrent navigation or page.close() happens while verifyRedditIdentity is evaluating.
  4. Test network from the automation browser directly; fix proxy/TLS issues if fetch fails at the network layer.

Example fix

// before: evaluate racing a navigation
await Promise.all([page.goto('https://www.reddit.com/'), verifyRedditIdentity(page)]);
// after: sequence the calls
await page.goto('https://www.reddit.com/');
await verifyRedditIdentity(page);
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the page is alive and settled before evaluating
await page.goto('https://www.reddit.com/', { waitUntil: 'load' });
if (page.isClosed?.()) throw new Error('page closed before probe');

Try / catch

try {
  const me = await opencli.reddit.whoami();
} catch (e) {
  if (/Reddit whoami failed/.test(e.message)) {
    console.error('In-page probe failed:', e.message); // inspect detail, retry or check network
  }
  throw e;
}

Prevention

When it happens

Trigger: The fetch itself rejects inside the page context: network error/TLS failure, page navigated mid-evaluate killing the async fetch, CORS/context issues, or res.json() throwing on a non-JSON body (e.g. an HTML block page).

Common situations: Reddit serving a quarantine/block interstitial HTML instead of JSON; flaky network in the automation browser; page.close() or navigation racing the evaluate; corporate MITM proxy breaking TLS.

Related errors


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