jackwener/OpenCLI · error · CommandExecutionError

exception

Error message

exception

What it means

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.

Source

Thrown at clis/hf/auth.js:25

  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. Read probe.detail appended after 'HF whoami failed:' to identify the in-page exception
  2. Re-run the command; transient network errors often resolve on retry
  3. Verify huggingface.co is reachable from the browser environment (no CSP/extension/proxy interference)
  4. Update the CLI if HF changed the whoami-v2 response shape, breaking the probe

Example fix

// before
const probe = await page.evaluate(WHOAMI_PROBE); // throws 'exception'
// after
let probe; try { probe = await page.evaluate(WHOAMI_PROBE); } catch (e) { throw new CommandExecutionError(`HF probe crashed: ${e.message}`); }
Defensive patterns

Strategy: try-catch

Type guard

function isExceptionProbe(p) { return !!p && p.kind === 'exception' && typeof p.detail === 'string'; }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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