jackwener/OpenCLI · error · AuthRequiredError

AuthRequiredError('gitee.com', probe.detail)

Error message

AuthRequiredError('gitee.com', probe.detail)

What it means

verifyGiteeIdentity in clis/gitee/auth.js probes https://gitee.com/api/v5/user from inside the logged-in browser page. When that endpoint answers 401/403, or returns JSON without id/login (anonymous), the probe reports kind 'auth' and this AuthRequiredError('gitee.com', detail) is thrown. It signals that no valid Gitee session exists and an interactive login (https://gitee.com/login) is required before the command can proceed.

Source

Thrown at clis/gitee/auth.js:23

// rotates, so the poll uses a no-navigation API probe instead of a cookie gate.
const WHOAMI_PROBE = `(async () => {
  try {
    const r = await fetch('/api/v5/user', { credentials: 'include', headers: { Accept: 'application/json' } });
    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Gitee /api/v5/user HTTP ' + r.status };
    if (!r.ok) return { kind: 'http', httpStatus: r.status };
    const d = await r.json();
    if (!d || !d.id || !d.login) return { kind: 'auth', detail: 'Gitee /api/v5/user has no id/login — anonymous' };
    return { ok: true, user_id: String(d.id), username: String(d.login), name: String(d.name || '') };
  } catch (e) {
    return { kind: 'exception', detail: String(e && e.message || e) };
  }
})()`;

async function verifyGiteeIdentity(page) {
  await page.goto('https://gitee.com/');
  await page.wait(1);
  const probe = await page.evaluate(WHOAMI_PROBE);
  if (probe?.kind === 'auth') throw new AuthRequiredError('gitee.com', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Gitee /api/v5/user`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`Gitee whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Gitee probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, username: probe.username, name: probe.name };
}

registerSiteAuthCommands({
  site: 'gitee',
  domain: 'gitee.com',
  loginUrl: 'https://gitee.com/login',
  columns: ['user_id', 'username', 'name'],
  verify: verifyGiteeIdentity,
  poll: async (page) => {
    const probe = await page.evaluate(WHOAMI_PROBE);
    if (!probe?.ok) throw new AuthRequiredError('gitee.com', 'Waiting for Gitee login');
    return { user_id: probe.user_id, username: probe.username, name: probe.name };
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the gitee login command and complete the interactive login at https://gitee.com/login in the automated browser.
  2. Re-run the whoami/verify command afterwards to confirm the session is valid.
  3. If login keeps failing, clear the browser profile cookies and log in again.
  4. Check that the Gitee account is not suspended and the password has not recently changed (invalidates sessions).

Example fix

// before — probing identity without a session
const who = await verifyGiteeIdentity(page); // throws AuthRequiredError
// after — catch and prompt login
try {
  const who = await verifyGiteeIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await runGiteeLogin(page); // navigates to https://gitee.com/login
    const who = await verifyGiteeIdentity(page);
  } else throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

const res = await fetch('https://gitee.com/api/v5/user', { credentials: 'include' });
if (res.status === 401 || res.status === 403) {
  throw new Error('Not logged in to gitee.com — run login first');
}

Type guard

function isAuthRequiredError(e) { return e && e.name === 'AuthRequiredError'; }

Try / catch

try {
  const identity = await verifyGiteeIdentity(page);
} catch (err) {
  if (err.name === 'AuthRequiredError') {
    // launch interactive login at https://gitee.com/login, then re-verify
  } else throw err;
}

Prevention

When it happens

Trigger: Running any Gitee auth command (login --verify / whoami flows registered via registerSiteAuthCommands) while the browser has no valid gitee session cookie: /api/v5/user returns 401 or 403, or returns 200 with an anonymous body lacking id/login.

Common situations: Session cookie expired or was revoked on the server; using a fresh browser profile that never logged in; logging out of gitee.com in the automated browser; Gitee invalidating sessions after a password change or security event.

Related errors


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