jackwener/OpenCLI · error · CommandExecutionError

Unexpected Gitee probe: ${JSON.stringify(probe)}

Error message

Unexpected Gitee probe: ${JSON.stringify(probe)}

What it means

The final guard in verifyGiteeIdentity (clis/gitee/auth.js): if the probe result is neither ok, auth, http, nor exception, it throws this CommandExecutionError with the JSON of the whole probe object. It means the WHOAMI_PROBE returned a shape the code does not recognize — a contract violation between the in-page script and the Node-side verification.

Source

Thrown at clis/gitee/auth.js:26

    const r = await fetch('/api/v5/user', { credentials: 'include', headers: { Accept: 'application/json' } });
    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Gitee /api/v5/user HTTP ' + r.status };
    if (!r.ok) return { kind: 'http', httpStatus: r.status };
    const d = await r.json();
    if (!d || !d.id || !d.login) return { kind: 'auth', detail: 'Gitee /api/v5/user has no id/login — anonymous' };
    return { ok: true, user_id: String(d.id), username: String(d.login), name: String(d.name || '') };
  } catch (e) {
    return { kind: 'exception', detail: String(e && e.message || e) };
  }
})()`;

async function verifyGiteeIdentity(page) {
  await page.goto('https://gitee.com/');
  await page.wait(1);
  const probe = await page.evaluate(WHOAMI_PROBE);
  if (probe?.kind === 'auth') throw new AuthRequiredError('gitee.com', probe.detail);
  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Gitee /api/v5/user`);
  if (probe?.kind === 'exception') throw new CommandExecutionError(`Gitee whoami failed: ${probe.detail}`);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Gitee probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, username: probe.username, name: probe.name };
}

registerSiteAuthCommands({
  site: 'gitee',
  domain: 'gitee.com',
  loginUrl: 'https://gitee.com/login',
  columns: ['user_id', 'username', 'name'],
  verify: verifyGiteeIdentity,
  poll: async (page) => {
    const probe = await page.evaluate(WHOAMI_PROBE);
    if (!probe?.ok) throw new AuthRequiredError('gitee.com', 'Waiting for Gitee login');
    return { user_id: probe.user_id, username: probe.username, name: probe.name };
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the JSON in the message: null/undefined usually means the page context died during evaluation.
  2. Re-navigate to https://gitee.com/ and retry; if it recurs, restart the browser/profile.
  3. Check for extensions or middleware injecting/rewriting page scripts on gitee.com.
  4. If you customized WHOAMI_PROBE, ensure it returns one of the documented kinds: auth, http, exception, or ok.

Example fix

// before — evaluating on a page that may have navigated away
const probe = await page.evaluate(WHOAMI_PROBE);
// after — validate probe shape before verify
const probe = await page.evaluate(WHOAMI_PROBE);
if (probe == null) throw new Error('Probe returned null — page context lost');
Defensive patterns

Strategy: type-guard

Validate before calling

const probe = await page.evaluate(WHOAMI_PROBE);
if (probe == null || typeof probe !== 'object' || !('kind' in probe || 'ok' in probe)) {
  throw new Error('Probe shape invalid — page context likely lost');
}

Type guard

function isWellFormedProbe(p) {
  return p != null && typeof p === 'object' &&
    (p.ok === true || ['auth', 'http', 'exception'].includes(p.kind));
}

Try / catch

try {
  const identity = await verifyGiteeIdentity(page);
} catch (err) {
  if (err.message.startsWith('Unexpected Gitee probe:')) {
    // parse the JSON payload in the message; re-navigate and retry once
  } else throw err;
}

Prevention

When it happens

Trigger: page.evaluate returns null/undefined (context destroyed or evaluation wrapper swallowed the result), the probe script was truncated/altered by page CSP or a rewriter, or a modified probe returns a new kind value not covered by the switch.

Common situations: The browser tab navigated or crashed so page.evaluate resolved to null; a proxy or injecting extension rewriting page scripts; a locally patched/custom probe returning an unexpected payload shape.

Related errors


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