{"record":{"id":"d100017225da5172","repo":"jackwener/OpenCLI","slug":"kimi-whoami-failed-result-detail","errorCode":null,"errorMessage":"Kimi whoami failed: ${result.detail}","messagePattern":"Kimi whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/kimi/auth.js","lineNumber":39,"sourceCode":"    try {\n      const token = ${JSON.stringify(token)};\n      const res = await fetch('/api/user', { credentials: 'include', headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Kimi /api/user HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (!d || !d.id) {\n        return { kind: 'auth', detail: 'Kimi /api/user returned no id — anonymous' };\n      }\n      return { ok: true, user_id: String(d.id), name: String(d.name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('kimi.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/user`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Kimi whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Kimi probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'kimi',\n  domain: 'kimi.com',\n  loginUrl: 'https://www.kimi.com/',\n  columns: ['user_id', 'name'],\n  quickCheck: hasKimiSessionCookie,\n  verify: verifyKimiIdentity,\n  poll: async (page) => {\n    if (!await hasKimiSessionCookie(page)) {\n      throw new AuthRequiredError('kimi.com', 'Waiting for Kimi auth cookies');\n    }\n    return verifyKimiIdentity(page);\n  },\n});","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/kimi/auth.js#L21-L57","documentation":"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.","triggerScenarios":"The evaluated async function throws: fetch rejects (network down, DNS failure, request blocked), response parsing fails, or page navigation/context destroyed mid-evaluate.","commonSituations":"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.","solutions":["Read `result.detail` in the message to identify the underlying exception (network vs parse vs context)","Verify general connectivity to www.kimi.com from the browser profile","Retry the command — transient network failures often clear","Ensure the page stays on kimi.com and is not navigated/closed while verify runs"],"exampleFix":"// before\nconst result = await page.evaluate(probe); // throws: Failed to fetch\n// after\ntry {\n  const result = await page.evaluate(probe);\n} catch (e) {\n  await page.wait(5);\n  const result = await page.evaluate(probe); // retry transient network errors\n}","handlingStrategy":"try-catch","validationCode":"// check basic reachability before in-page probe\nconst reachable = await page.evaluate(`fetch('https://www.kimi.com/', {method:'HEAD'}).then(r => true).catch(() => false)`);\nif (!reachable) throw new Error('kimi.com unreachable — check network/proxy');","typeGuard":"function isProbeException(r) {\n  return !!r && typeof r === 'object' && r.kind === 'exception' && typeof r.detail === 'string';\n}","tryCatchPattern":"try {\n  await kimiWhoami();\n} catch (e) {\n  if (/whoami failed/i.test(e.message)) {\n    console.error('In-page probe failed:', e.message);\n    await sleep(5000);\n    await kimiWhoami(); // retry once for transient network errors\n  } else throw e;\n}","preventionTips":["Ensure the page remains on kimi.com and un-navigated while probes run","Verify DNS/proxy access to www.kimi.com in the automation environment","Log result.detail to distinguish network vs parsing failures"],"tags":["kimi","network","evaluate-exception","api"],"backgroundTag":"in-page-fetch-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}