jackwener/OpenCLI · error · CommandExecutionError

Unexpected Reddit probe: ${JSON.stringify(result)}

Error message

Unexpected Reddit probe: ${JSON.stringify(result)}

What it means

CommandExecutionError thrown as a catch-all in verifyRedditIdentity when the probe result is neither ok, auth, http, nor exception — i.e. the in-page script returned an unexpected shape (or null/undefined). This guards against unanticipated probe payloads and bug fixes in the page script being silently ignored.

Source

Thrown at clis/reddit/auth.js:35

      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 once to rule out a transient destroyed-context evaluate.
  2. Update the CLI/automation driver pair to compatible versions so evaluate results serialize as expected.
  3. Inspect the JSON in the message — it shows the actual unexpected result and narrows the cause.
  4. If reproducible, capture browser console/page state at evaluate time to see why the probe returned a malformed value.

Example fix

// before: page torn down during evaluate
await page.close(); const r = await verifyRedditIdentity(page);
// after: verify before closing
const r = await verifyRedditIdentity(page); await page.close();
Defensive patterns

Strategy: type-guard

Validate before calling

// keep the page open and idle while probing
if (page.isClosed?.()) throw new Error('page already closed');

Type guard

function isProbeResult(r) {
  return !!r && typeof r === 'object' && typeof r.kind === 'string' &&
    ['ok','auth','http','exception'].includes(r.kind);
}

Try / catch

try {
  const me = await opencli.reddit.whoami();
} catch (e) {
  if (/Unexpected Reddit probe/.test(e.message)) {
    // malformed probe result: check driver versions / page lifecycle
    console.error(e.message);
  }
  throw e;
}

Prevention

When it happens

Trigger: The page.evaluate result lacks the expected `kind`/`ok` fields — e.g. the evaluate returned undefined because the page context was destroyed mid-script, or a wrapper/driver serialized the result differently than expected.

Common situations: Automation driver version mismatch changing evaluate serialization; page crashed/navigated during evaluation returning null; modifications to the probe script returning an undocumented shape.

Related errors


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