jackwener/OpenCLI · error · CommandExecutionError

Kimi whoami failed: ${result.detail}

Error message

Kimi whoami failed: ${result.detail}

What it means

The `/api/user` probe runs inside page.evaluate inside a try/catch; any in-page exception (network failure, CSP block, fetch rejection, JSON parse error) is captured as `{kind:'exception', detail}` and rethrown as CommandExecutionError. It means the whoami check itself failed to execute or complete, not that the user is unauthenticated.

Source

Thrown at clis/kimi/auth.js:39

    try {
      const token = ${JSON.stringify(token)};
      const res = await fetch('/api/user', { credentials: 'include', headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' } });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'Kimi /api/user HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      if (!d || !d.id) {
        return { kind: 'auth', detail: 'Kimi /api/user returned no id — anonymous' };
      }
      return { ok: true, user_id: String(d.id), name: String(d.name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`);
  if (result?.kind === 'auth') throw new AuthRequiredError('kimi.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/user`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Kimi whoami failed: ${result.detail}`);
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Kimi probe: ${JSON.stringify(result)}`);
  return { user_id: result.user_id, name: result.name };
}

registerSiteAuthCommands({
  site: 'kimi',
  domain: 'kimi.com',
  loginUrl: 'https://www.kimi.com/',
  columns: ['user_id', 'name'],
  quickCheck: hasKimiSessionCookie,
  verify: verifyKimiIdentity,
  poll: async (page) => {
    if (!await hasKimiSessionCookie(page)) {
      throw new AuthRequiredError('kimi.com', 'Waiting for Kimi auth cookies');
    }
    return verifyKimiIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read `result.detail` in the message to identify the underlying exception (network vs parse vs context)
  2. Verify general connectivity to www.kimi.com from the browser profile
  3. Retry the command — transient network failures often clear
  4. Ensure the page stays on kimi.com and is not navigated/closed while verify runs

Example fix

// before
const result = await page.evaluate(probe); // throws: Failed to fetch
// after
try {
  const result = await page.evaluate(probe);
} catch (e) {
  await page.wait(5);
  const result = await page.evaluate(probe); // retry transient network errors
}
Defensive patterns

Strategy: try-catch

Validate before calling

// check basic reachability before in-page probe
const reachable = await page.evaluate(`fetch('https://www.kimi.com/', {method:'HEAD'}).then(r => true).catch(() => false)`);
if (!reachable) throw new Error('kimi.com unreachable — check network/proxy');

Type guard

function isProbeException(r) {
  return !!r && typeof r === 'object' && r.kind === 'exception' && typeof r.detail === 'string';
}

Try / catch

try {
  await kimiWhoami();
} catch (e) {
  if (/whoami failed/i.test(e.message)) {
    console.error('In-page probe failed:', e.message);
    await sleep(5000);
    await kimiWhoami(); // retry once for transient network errors
  } else throw e;
}

Prevention

When it happens

Trigger: The evaluated async function throws: fetch rejects (network down, DNS failure, request blocked), response parsing fails, or page navigation/context destroyed mid-evaluate.

Common situations: Running without internet access or behind a corporate proxy that blocks www.kimi.com; browser context closed or navigated during the probe; Kimi endpoint path changed so the fetch 404s in a way the script treats as an exception; CSP or extension interfering with in-page fetch.

Related errors


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