{"record":{"id":"49b5ef5e3b34acfa","repo":"jackwener/OpenCLI","slug":"exception","errorCode":null,"errorMessage":"exception","messagePattern":"exception","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/auth.js","lineNumber":25,"sourceCode":"  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":7,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/auth.js#L7-L42","documentation":"verifyHfIdentity's in-page probe caught a JavaScript exception while calling /api/whoami-v2 (probe.kind === 'exception'). The library rethrows it as a CommandExecutionError with message 'exception' and the probe's detail, distinguishing page-script failures from HTTP and auth outcomes.","triggerScenarios":"The WHOAMI_PROBE script throws inside page.evaluate — e.g. fetch rejected due to network/DNS/CSP block, or JSON parsing of the response threw inside the page context.","commonSituations":"Browser page blocked by CSP or extensions; network interruption mid-probe; HF returns HTML instead of JSON causing probe-side parse failure; stale page context after navigation.","solutions":["Read probe.detail appended after 'HF whoami failed:' to identify the in-page exception","Re-run the command; transient network errors often resolve on retry","Verify huggingface.co is reachable from the browser environment (no CSP/extension/proxy interference)","Update the CLI if HF changed the whoami-v2 response shape, breaking the probe"],"exampleFix":"// before\nconst probe = await page.evaluate(WHOAMI_PROBE); // throws 'exception'\n// after\nlet probe; try { probe = await page.evaluate(WHOAMI_PROBE); } catch (e) { throw new CommandExecutionError(`HF probe crashed: ${e.message}`); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isExceptionProbe(p) { return !!p && p.kind === 'exception' && typeof p.detail === 'string'; }","tryCatchPattern":"try { await verifyHfIdentity(page); } catch (e) { if (String(e.message).startsWith('exception')) { console.error('in-page probe failed:', e.message); /* retry or fall back to manual check */ } else throw e; }","preventionTips":["Keep browser environment free of CSP-blocking extensions","Retry once on transient network exceptions","Keep the CLI updated for HF response-shape changes","Confirm DNS/network reachability before browser automation"],"tags":["exception","huggingface","browser","whoami"],"backgroundTag":"in-page-script-exception","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}