{"record":{"id":"437db0742072fdc9","repo":"jackwener/OpenCLI","slug":"unexpected-xueqiu-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected xueqiu probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected xueqiu probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xueqiu/auth.js","lineNumber":46,"sourceCode":"      }\n      if (d?.error_code) {\n        return { kind: 'xq-error', errorCode: d.error_code, detail: d.error_description || 'xueqiu API error' };\n      }\n      const uCookie = document.cookie.split('; ').find(c => c.startsWith('u='))?.split('=')[1] || '';\n      const cookiesuCookie = document.cookie.split('; ').find(c => c.startsWith('cookiesu='))?.split('=')[1] || '';\n      if (!uCookie || uCookie === cookiesuCookie) {\n        return { kind: 'auth', detail: 'xueqiu u cookie equals cookiesu (device id) — anonymous despite portfolio API 200' };\n      }\n      return { ok: true, user_id: uCookie };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('xueqiu.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from xueqiu stock API: ${probe.detail || ''}`);\n  if (probe?.kind === 'xq-error') throw new CommandExecutionError(`xueqiu API error_code ${probe.errorCode}: ${probe.detail}`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`xueqiu whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected xueqiu probe: ${JSON.stringify(probe)}`);\n  return { user_id: String(probe.user_id) };\n}\n\nregisterSiteAuthCommands({\n  site: 'xueqiu',\n  domain: 'xueqiu.com',\n  loginUrl: 'https://xueqiu.com/',\n  columns: ['user_id'],\n  quickCheck: hasXueqiuAccessToken,\n  verify: verifyXueqiuIdentity,\n  poll: async (page) => {\n    if (!await hasXueqiuAccessToken(page)) {\n      throw new AuthRequiredError('xueqiu.com', 'Waiting for Xueqiu xq_a_token cookie');\n    }\n    return verifyXueqiuIdentity(page);\n  },\n});\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xueqiu/auth.js#L28-L64","documentation":"Final safety net in verifyXueqiuIdentity: if the probe result is neither ok nor any known kind (auth/http/xq-error/exception), the verifier throws CommandExecutionError with the JSON-serialized probe. This guards against an unexpected probe shape — typically null/undefined from page.evaluate returning nothing or the probe protocol changing.","triggerScenarios":"page.evaluate returns null/undefined (page closed, script failed to serialize) or the in-page script returns an object without a recognized kind and without ok:true.","commonSituations":"Browser crashed or page navigated during evaluate so the promise resolved to null; an older/newer browser driver returning a non-serializable result; library-internal contract drift between the probe script and the verifier.","solutions":["Re-run the command — a transient evaluate failure often resolves on retry","Ensure the automation browser stays open on xueqiu.com during verify (avoid navigating away mid-probe)","Re-login and retry; if it persists, report with the JSON probe shown in the message","Check for library updates if the probe script and verifier could be out of sync"],"exampleFix":"// before\nawait page.goto('other-site');\nawait verifyXueqiuIdentity(page);\n// after\nawait page.goto('https://xueqiu.com/');\nawait verifyXueqiuIdentity(page);","handlingStrategy":"try-catch","validationCode":"// ensure the page is on xueqiu before verifying\nconst url = page.url();\nif (!url.includes('xueqiu.com')) await page.goto('https://xueqiu.com/');","typeGuard":"function isKnownProbe(p) {\n  return !!p && typeof p === 'object'\n    && ['auth','http','xq-error','exception'].includes(p.kind) || p?.ok === true;\n}","tryCatchPattern":"try {\n  await verifyXueqiuIdentity(page);\n} catch (e) {\n  if (e.message.startsWith('Unexpected xueqiu probe')) {\n    // transient evaluate failure — retry once\n    await verifyXueqiuIdentity(page);\n  } else throw e;\n}","preventionTips":["Keep the browser page on xueqiu.com for the whole verify call","Do not navigate or close the page while verify is in flight","Retry transient failures once before reporting","Report persistent occurrences with the embedded probe JSON to maintainers"],"tags":["xueqiu","defensive","unexpected-state"],"backgroundTag":"unexpected-probe-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}