jackwener/OpenCLI · error · AuthRequiredError

hupu.com

Error message

hupu.com

What it means

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.

Source

Thrown at clis/hupu/auth.js:11

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasHupuUserCookie(page) {
  const cookies = await page.getCookies({ url: 'https://my.hupu.com' });
  return cookies.some(c => c.name === 'u' && c.value);
}

async function verifyHupuIdentity(page) {
  if (!await hasHupuUserCookie(page)) {
    throw new AuthRequiredError('hupu.com', 'Hupu u cookie missing — anonymous');
  }
  await page.goto('https://my.hupu.com/');
  await page.wait(2);
  const probe = await page.evaluate(`
    (() => {
      if (/passport\\.hupu\\.com\\/.*login/.test(location.href)) {
        return { kind: 'auth', detail: 'Hupu my page redirected to passport login' };
      }
      const uCookie = (document.cookie.split('; ').find(c => c.startsWith('u=')) || '').split('=')[1] || '';
      const el = document.querySelector('.user-name, .username, .nick, [class*="userName"]');
      const username = (el?.innerText || '').trim();
      if (!uCookie) {
        return { kind: 'auth', detail: 'Hupu my page rendered but u cookie absent — stale session' };
      }
      return { ok: true, user_id: uCookie, username };
    })()
  `);
  if (probe?.kind === 'auth') throw new AuthRequiredError('hupu.com', probe.detail);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to hupu.com in the managed browser session, then rerun the command
  2. Point the CLI at a browser profile that has an authenticated Hupu session
  3. Clear and re-establish cookies via a fresh interactive login
  4. Check the cookie domain/URL (https://my.hupu.com) is reachable so cookies load
Defensive patterns

Strategy: try-catch

Validate before calling

const cookies = await page.getCookies({ url: 'https://my.hupu.com' });
if (!cookies.some(c => c.name === 'u' && c.value)) await openInteractiveLogin();

Type guard

const hasHupuCookie = cookies => Array.isArray(cookies) && cookies.some(c => c.name === 'u' && Boolean(c.value));

Try / catch

try { const identity = await verifyHupuIdentity(page); } catch (e) { if (e instanceof AuthRequiredError) { await runLoginFlow(page); return verifyHupuIdentity(page); } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Fresh browser profile never logged in; session cookies expired/cleared; running headless with a profile that lacks credentials; logout elsewhere invalidating the session.

Related errors


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