jackwener/OpenCLI · error · CommandExecutionError

http

Error message

http

What it means

verifyHfIdentity probes Hugging Face's /api/whoami-v2 in the browser page. When the probe returns kind='http', it means the whoami endpoint answered with a non-success HTTP status (e.g. 401/403/500), so a CommandExecutionError with 'http' as the message prefix is thrown to report the transport-level failure distinct from an auth redirect.

Source

Thrown at clis/hf/auth.js:24

const WHOAMI_PROBE = `(async () => {
  try {
    const r = await fetch('/api/whoami-v2', { credentials: 'include', headers: { Accept: 'application/json' } });
    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'HF /api/whoami-v2 HTTP ' + r.status };
    if (!r.ok) return { kind: 'http', httpStatus: r.status };
    const d = await r.json();
    if (!d || !d.name || d.type === undefined) return { kind: 'auth', detail: 'HF /api/whoami-v2 has no name — anonymous' };
    return { ok: true, username: String(d.name), fullname: String(d.fullname || ''), type: String(d.type || '') };
  } catch (e) {
    return { kind: 'exception', detail: String(e && e.message || e) };
  }
})()`;

async function verifyHfIdentity(page) {
  await page.goto('https://huggingface.co/');
  await page.wait(1);
  const probe = await page.evaluate(WHOAMI_PROBE);
  if (probe?.kind === 'auth') throw new AuthRequiredError('huggingface.co', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from HF /api/whoami-v2`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`HF whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected HF probe: ${JSON.stringify(probe)}`);
  return { username: probe.username, fullname: probe.fullname, type: probe.type };
}

registerSiteAuthCommands({
  site: 'hf',
  domain: 'huggingface.co',
  loginUrl: 'https://huggingface.co/login',
  columns: ['username', 'fullname', 'type'],
  verify: verifyHfIdentity,
  poll: async (page) => {
    const probe = await page.evaluate(WHOAMI_PROBE);
    if (!probe?.ok) throw new AuthRequiredError('huggingface.co', 'Waiting for Hugging Face login');
    return { username: probe.username, fullname: probe.fullname, type: probe.type };
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Check https://huggingface.co status / retry after the API outage resolves
  2. Wait and retry if rate-limited (HTTP 429), reducing call frequency
  3. Inspect probe.httpStatus in the message to see the exact status and address it (proxy allowlist, credentials)
  4. Re-run hf auth login to refresh the session if the status is 401/403

Example fix

// before
await verifyHfIdentity(page); // throws on transient 5xx
// after
try { await verifyHfIdentity(page); } catch (e) { if (String(e.message).includes('HTTP 5')) await sleep(2000); await verifyHfIdentity(page); }
Defensive patterns

Strategy: retry

Validate before calling

const ok = await fetch('https://huggingface.co/api/whoami-v2').then(r => r.ok).catch(() => false);
if (!ok) throw new Error('HF API unreachable or non-2xx; fix network/outage before running');

Type guard

function isHttpProbe(p) { return !!p && p.kind === 'http' && typeof p.httpStatus === 'number'; }

Try / catch

try { await verifyHfIdentity(page); } catch (e) { if (String(e.message).startsWith('http') || /HTTP \d+/.test(e.message)) { await backoffRetry(() => verifyHfIdentity(page), 3); } else throw e; }

Prevention

When it happens

Trigger: The in-page WHOAMI_PROBE fetch of /api/whoami-v2 returns a non-2xx status that is not classified as auth (probe.kind === 'http'), e.g. HF returns 5xx during an outage or a rate-limit/429 response.

Common situations: Hugging Face API outage or maintenance; hitting API rate limits; corporate proxy returning 403/502 pages; the probe's fetch failing at HTTP layer while the main page still loads.

Related errors


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