{"record":{"id":"1f25cdb003b7d6b4","repo":"jackwener/OpenCLI","slug":"unexpected-gitee-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Gitee probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Gitee probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gitee/auth.js","lineNumber":26,"sourceCode":"    const r = await fetch('/api/v5/user', { credentials: 'include', headers: { Accept: 'application/json' } });\n    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Gitee /api/v5/user HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    if (!d || !d.id || !d.login) return { kind: 'auth', detail: 'Gitee /api/v5/user has no id/login — anonymous' };\n    return { ok: true, user_id: String(d.id), username: String(d.login), name: String(d.name || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyGiteeIdentity(page) {\n  await page.goto('https://gitee.com/');\n  await page.wait(1);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('gitee.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Gitee /api/v5/user`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Gitee whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Gitee probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, username: probe.username, name: probe.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'gitee',\n  domain: 'gitee.com',\n  loginUrl: 'https://gitee.com/login',\n  columns: ['user_id', 'username', 'name'],\n  verify: verifyGiteeIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('gitee.com', 'Waiting for Gitee login');\n    return { user_id: probe.user_id, username: probe.username, name: probe.name };\n  },\n});\n","sourceCodeStart":8,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gitee/auth.js#L8-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the JSON in the message: null/undefined usually means the page context died during evaluation.","Re-navigate to https://gitee.com/ and retry; if it recurs, restart the browser/profile.","Check for extensions or middleware injecting/rewriting page scripts on gitee.com.","If you customized WHOAMI_PROBE, ensure it returns one of the documented kinds: auth, http, exception, or ok."],"exampleFix":"// before — evaluating on a page that may have navigated away\nconst probe = await page.evaluate(WHOAMI_PROBE);\n// after — validate probe shape before verify\nconst probe = await page.evaluate(WHOAMI_PROBE);\nif (probe == null) throw new Error('Probe returned null — page context lost');","handlingStrategy":"type-guard","validationCode":"const probe = await page.evaluate(WHOAMI_PROBE);\nif (probe == null || typeof probe !== 'object' || !('kind' in probe || 'ok' in probe)) {\n  throw new Error('Probe shape invalid — page context likely lost');\n}","typeGuard":"function isWellFormedProbe(p) {\n  return p != null && typeof p === 'object' &&\n    (p.ok === true || ['auth', 'http', 'exception'].includes(p.kind));\n}","tryCatchPattern":"try {\n  const identity = await verifyGiteeIdentity(page);\n} catch (err) {\n  if (err.message.startsWith('Unexpected Gitee probe:')) {\n    // parse the JSON payload in the message; re-navigate and retry once\n  } else throw err;\n}","preventionTips":["Confirm the tab has not navigated/crashed before calling page.evaluate.","Keep WHOAMI_PROBE unmodified and returning one of the documented kinds.","Treat a null evaluate result as a page-context failure, not an auth problem.","Log the full probe JSON (it is already embedded in the message) when diagnosing."],"tags":["gitee","unexpected-state","contract-violation","browser-automation"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}