{"record":{"id":"1c6f4cd861423d34","repo":"jackwener/OpenCLI","slug":"exception-1c6f4c","errorCode":null,"errorMessage":"exception","messagePattern":"exception","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xueqiu/auth.js","lineNumber":45,"sourceCode":"        return { kind: 'auth', detail: 'xueqiu portfolio API error_code 60201 用户id无效 — anonymous' };\n      }\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});","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xueqiu/auth.js#L27-L63","documentation":"The in-page probe wraps its whole fetch in try/catch and returns { kind: 'exception', detail }; verifyXueqiuIdentity converts that into CommandExecutionError 'xueqiu whoami failed: <detail>'. It means the identity probe itself crashed in the browser — network failure, CORS, JSON parse failure, or a page context issue — rather than xueqiu answering with an error.","triggerScenarios":"page.evaluate's fetch throws inside the browser: network outage, DNS failure, aborted request, res.json() parse error on a non-JSON 200 body, or the evaluate script erroring.","commonSituations":"Running in an offline/proxy-restricted environment; xueqiu returning HTML with 200 so res.json() throws; browser page navigated/closed mid-probe; corporate proxy blocking stock.xueqiu.com.","solutions":["Check network connectivity and proxy settings for the automation browser","Visit https://xueqiu.com/ in the browser first so the origin/context is stable, then re-run verify","Re-run with --verbose to see the exception detail string","If detail mentions JSON parsing, the API may be returning HTML — complete any challenge then retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isExceptionProbe(p) {\n  return !!p && typeof p === 'object' && p.kind === 'exception' && typeof p.detail === 'string';\n}","tryCatchPattern":"try {\n  await verifyXueqiuIdentity(page);\n} catch (e) {\n  if (e.message.startsWith('xueqiu whoami failed')) {\n    console.error('In-page probe crashed:', e.message);\n    // check network/proxy, navigate to xueqiu.com, then retry\n  } else throw e;\n}","preventionTips":["Verify network/DNS/proxy reachability to stock.xueqiu.com before running","Navigate to https://xueqiu.com/ before verify so the page context is stable","Avoid closing or navigating the automation browser mid-probe","Use --verbose to capture the underlying exception detail"],"tags":["network","browser","xueqiu","exception"],"backgroundTag":"in-page-fetch-exception","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}