{"record":{"id":"3b68cdc1c482b8ff","repo":"jackwener/OpenCLI","slug":"unexpected-hf-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected HF probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected HF probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/hf/auth.js","lineNumber":26,"sourceCode":"    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":8,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hf/auth.js#L8-L42","documentation":"verifyHfIdentity throws this when the whoami probe returns an object that is neither ok nor a recognized kind ('auth'/'http'/'exception'), i.e. an unrecognized probe shape. The message 'Unexpected HF probe: ...' embeds the JSON of the probe for debugging — this guards against HF response-shape drift or probe bugs.","triggerScenarios":"probe exists but probe.ok is falsy and probe.kind doesn't match any handled branch — e.g. HF's /api/whoami-v2 response shape changed, or the probe returned null/undefined fields after a site update.","commonSituations":"Hugging Face renamed or restructured whoami-v2 fields; a CLI version outdated relative to the site; the probe script silently produced {ok:false} without a kind.","solutions":["Inspect the JSON in the message to see the actual probe shape","Update the opencli package to the latest version compatible with current HF API","Verify /api/whoami-v2 manually (curl with cookies) to compare its response shape","Report/patch WHOAMI_PROBE if HF changed field names"],"exampleFix":"// before\n// outdated probe expects {ok, username, ...}\n// after\nnpm update opencli  // pull updated WHOAMI_PROBE matching new HF response shape","handlingStrategy":"try-catch","validationCode":"const r = await fetch('https://huggingface.co/api/whoami-v2'); const body = await r.json(); if (!body || typeof body.name !== 'string') console.warn('unexpected whoami shape, update CLI');","typeGuard":"function isKnownProbe(p) { return !!p && ['auth','http','exception'].includes(p.kind) || p?.ok === true; }","tryCatchPattern":"try { await verifyHfIdentity(page); } catch (e) { if (String(e.message).startsWith('Unexpected HF probe:')) { const probe = JSON.parse(e.message.slice('Unexpected HF probe:'.length)); console.error('unknown probe shape', probe); } else throw e; }","preventionTips":["Pin/update opencli version matching current HF API","Log full probe JSON on failure for diagnosis","Spot-check whoami-v2 response shape after HF announcements","Wrap probe result parsing defensively"],"tags":["huggingface","schema-mismatch","whoami","defensive"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}