{"record":{"id":"5a9af5862ec4287b","repo":"jackwener/OpenCLI","slug":"http","errorCode":null,"errorMessage":"http","messagePattern":"http","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/auth.js","lineNumber":24,"sourceCode":"const WHOAMI_PROBE = `(async () => {\n  try {\n    const r = await fetch('/api/whoami-v2', { credentials: 'include', headers: { Accept: 'application/json' } });\n    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'HF /api/whoami-v2 HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    if (!d || !d.name || d.type === undefined) return { kind: 'auth', detail: 'HF /api/whoami-v2 has no name — anonymous' };\n    return { ok: true, username: String(d.name), fullname: String(d.fullname || ''), type: String(d.type || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyHfIdentity(page) {\n  await page.goto('https://huggingface.co/');\n  await page.wait(1);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('huggingface.co', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from HF /api/whoami-v2`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`HF whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected HF probe: ${JSON.stringify(probe)}`);\n  return { username: probe.username, fullname: probe.fullname, type: probe.type };\n}\n\nregisterSiteAuthCommands({\n  site: 'hf',\n  domain: 'huggingface.co',\n  loginUrl: 'https://huggingface.co/login',\n  columns: ['username', 'fullname', 'type'],\n  verify: verifyHfIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('huggingface.co', 'Waiting for Hugging Face login');\n    return { username: probe.username, fullname: probe.fullname, type: probe.type };\n  },\n});\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/auth.js#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check https://huggingface.co status / retry after the API outage resolves","Wait and retry if rate-limited (HTTP 429), reducing call frequency","Inspect probe.httpStatus in the message to see the exact status and address it (proxy allowlist, credentials)","Re-run hf auth login to refresh the session if the status is 401/403"],"exampleFix":"// before\nawait verifyHfIdentity(page); // throws on transient 5xx\n// after\ntry { await verifyHfIdentity(page); } catch (e) { if (String(e.message).includes('HTTP 5')) await sleep(2000); await verifyHfIdentity(page); }","handlingStrategy":"retry","validationCode":"const ok = await fetch('https://huggingface.co/api/whoami-v2').then(r => r.ok).catch(() => false);\nif (!ok) throw new Error('HF API unreachable or non-2xx; fix network/outage before running');","typeGuard":"function isHttpProbe(p) { return !!p && p.kind === 'http' && typeof p.httpStatus === 'number'; }","tryCatchPattern":"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; }","preventionTips":["Monitor huggingface.co status before batch jobs","Add exponential backoff for transient 5xx/429","Set conservative request rates to avoid rate limits","Verify proxy/CA configuration in corporate environments"],"tags":["http","network","huggingface","whoami"],"backgroundTag":"http-probe-non-2xx","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}