{"record":{"id":"41f8b800f8de0c2e","repo":"jackwener/OpenCLI","slug":"hupu-com","errorCode":null,"errorMessage":"hupu.com","messagePattern":"hupu\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/hupu/auth.js","lineNumber":11,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\n\nasync function hasHupuUserCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://my.hupu.com' });\n  return cookies.some(c => c.name === 'u' && c.value);\n}\n\nasync function verifyHupuIdentity(page) {\n  if (!await hasHupuUserCookie(page)) {\n    throw new AuthRequiredError('hupu.com', 'Hupu u cookie missing — anonymous');\n  }\n  await page.goto('https://my.hupu.com/');\n  await page.wait(2);\n  const probe = await page.evaluate(`\n    (() => {\n      if (/passport\\\\.hupu\\\\.com\\\\/.*login/.test(location.href)) {\n        return { kind: 'auth', detail: 'Hupu my page redirected to passport login' };\n      }\n      const uCookie = (document.cookie.split('; ').find(c => c.startsWith('u=')) || '').split('=')[1] || '';\n      const el = document.querySelector('.user-name, .username, .nick, [class*=\"userName\"]');\n      const username = (el?.innerText || '').trim();\n      if (!uCookie) {\n        return { kind: 'auth', detail: 'Hupu my page rendered but u cookie absent — stale session' };\n      }\n      return { ok: true, user_id: uCookie, username };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('hupu.com', probe.detail);","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hupu/auth.js#L1-L29","documentation":"verifyHupuIdentity first checks for a non-empty 'u' cookie on my.hupu.com; if absent the user is anonymous, and an AuthRequiredError with site 'hupu.com' is thrown to signal that login is required before identity verification can proceed.","triggerScenarios":"Calling the hupu auth/whoami command without an active Hupu login in the browser profile — cookies for my.hupu.com contain no 'u' cookie with a value.","commonSituations":"Fresh browser profile never logged in; session cookies expired/cleared; running headless with a profile that lacks credentials; logout elsewhere invalidating the session.","solutions":["Log in to hupu.com in the managed browser session, then rerun the command","Point the CLI at a browser profile that has an authenticated Hupu session","Clear and re-establish cookies via a fresh interactive login","Check the cookie domain/URL (https://my.hupu.com) is reachable so cookies load"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://my.hupu.com' });\nif (!cookies.some(c => c.name === 'u' && c.value)) await openInteractiveLogin();","typeGuard":"const hasHupuCookie = cookies => Array.isArray(cookies) && cookies.some(c => c.name === 'u' && Boolean(c.value));","tryCatchPattern":"try { const identity = await verifyHupuIdentity(page); } catch (e) { if (e instanceof AuthRequiredError) { await runLoginFlow(page); return verifyHupuIdentity(page); } throw e; }","preventionTips":["Log in to hupu.com before running auth-dependent commands","Use a persistent browser profile that retains session cookies","Pre-check the 'u' cookie before invoking identity verification","Re-authenticate when cookies are cleared or expire"],"tags":["auth","cookies","login-required"],"backgroundTag":"auth-required-cookie-missing","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}