{"record":{"id":"d37eacc23607a531","repo":"jackwener/OpenCLI","slug":"no-avatar-found-not-logged-in","errorCode":null,"errorMessage":"No avatar found — not logged in?","messagePattern":"No avatar found — not logged in\\?","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/kimi/ui.js","lineNumber":164,"sourceCode":"        const data = await page.evaluate(`(() => {\n      ${IS_VISIBLE_JS}\n      const avatar = document.querySelector('img[src*=\"avatar.moonshot.cn\"]');\n      if (!avatar) return null;\n      // The display name + plan are siblings in a parent container.\n      let container = avatar;\n      for (let i = 0; i < 5; i++) { if (container.parentElement) container = container.parentElement; }\n      const spans = Array.from(container.querySelectorAll('span, div')).filter(isVisible)\n        .map((el) => (el.innerText || el.textContent || '').trim())\n        .filter((t) => t && t.length < 60);\n      const uniq = [...new Set(spans)];\n      return {\n        avatarUrl: avatar.src,\n        avatarAlt: avatar.alt || '',\n        labels: uniq.slice(0, 10),\n      };\n    })()`);\n        if (!data) {\n            throw new CommandExecutionError('No avatar found — not logged in?', '');\n        }\n        const rows = [\n            { Field: 'AvatarAlt', Value: data.avatarAlt || '(none)' },\n            { Field: 'AvatarUrl', Value: data.avatarUrl },\n        ];\n        data.labels.forEach((l, i) => rows.push({ Field: `Label[${i + 1}]`, Value: l }));\n        return rows;\n    },\n});\n\n// -------- model --------\ncli({\n    site: 'kimi',\n    name: 'model',\n    access: 'write',\n    description: 'Read the current Kimi model (e.g. \"K2.6 思考\") or switch by clicking the model dropdown. With no argument, returns current; with --list, opens dropdown + lists; with --set <name>, switches.',\n    domain: KIMI_DOMAIN,\n    strategy: Strategy.COOKIE,","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/kimi/ui.js#L146-L182","documentation":"The account/whoami-style command scrapes the Kimi page for the user's avatar element to report AvatarAlt, AvatarUrl and nearby labels. If the in-page script returns null (no avatar element found), the command throws CommandExecutionError with the hint 'not logged in?'. It exists to distinguish an unauthenticated page from a successful but empty profile read.","triggerScenarios":"The injected evaluate script finds no avatar element — the user is not logged in, the session cookie expired, or the page layout no longer contains the expected avatar selector.","commonSituations":"Automation running without a persisted login session; Kimi logged the account out between runs; changed UI removed/moved the avatar node; navigating to the profile page while on a login redirect.","solutions":["Log in to Kimi in the controlled browser and persist the session before running the command.","Re-authenticate: open Kimi manually, complete login, then retry.","Check you are on the intended Kimi page (not a login redirect).","Update the library if Kimi changed its avatar markup."],"exampleFix":"// before\nconst data = await page.evaluate(avatarScript); // throws if not logged in\n// after\nif (page.url().includes('login')) await performLogin(page);\nconst data = await page.evaluate(avatarScript);","handlingStrategy":"try-catch","validationCode":"// detect login redirect before scraping profile data\nif (page.url().includes('login')) throw new Error('Not logged in to Kimi');","typeGuard":"const hasAvatarData = (d) => !!d && typeof d.avatarUrl === 'string' && d.avatarUrl.length > 0;","tryCatchPattern":"try {\n  const info = await getKimiAccount(page);\n} catch (e) {\n  if (/No avatar found/.test(e.message)) {\n    await loginKimi(page); // re-establish session\n    return getKimiAccount(page);\n  }\n  throw e;\n}","preventionTips":["Persist cookies/session storage so automation runs stay authenticated.","Check session validity (profile endpoint or avatar presence) before batch jobs.","Alert on login-redirect URLs instead of letting scraping fail."],"tags":["authentication","dom-scraping","kimi"],"backgroundTag":"not-logged-in","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}