{"record":{"id":"213018a1a398ce8d","repo":"jackwener/OpenCLI","slug":"unexpected-zsxq-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected zsxq probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected zsxq probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/zsxq/auth.js","lineNumber":39,"sourceCode":"        if (r.status === 401 || r.status === 403) {\n          return { kind: 'auth', detail: 'zsxq /v2/users/self returned HTTP ' + r.status };\n        }\n        if (!r.ok) return { kind: 'http', httpStatus: r.status };\n        const d = await r.json();\n        if (d?.succeeded === false || !d?.resp_data?.user) {\n          return { kind: 'auth', detail: 'zsxq /v2/users/self returned succeeded=false — anonymous' };\n        }\n        const u = d.resp_data.user;\n        return { ok: true, user_id: String(u.user_id || u.id || ''), name: String(u.name || u.nickname || '') };\n      } catch (e) {\n        return { kind: 'exception', detail: String(e && e.message || e) };\n      }\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('zsxq.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from zsxq /v2/users/self`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`zsxq whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected zsxq probe: ${JSON.stringify(probe)}`);\n  if (!probe.user_id) {\n    throw new AuthRequiredError('zsxq.com', 'zsxq /v2/users/self 200 but user_id missing — incomplete session');\n  }\n  return { user_id: probe.user_id, name: probe.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'zsxq',\n  domain: 'zsxq.com',\n  loginUrl: 'https://wx.zsxq.com/login',\n  columns: ['user_id', 'name'],\n  verify: verifyZsxqIdentity,\n  // No-navigation poll: probe the API from the current page so the login-page\n  // QR code isn't reset by a goto on every interval.\n  poll: async (page) => {\n    const loggedIn = await page.evaluate(`(async () => {\n      try {\n        const r = await fetch('https://api.zsxq.com/v2/users/self', { credentials: 'include', headers: { Accept: 'application/json' } });","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zsxq/auth.js#L21-L57","documentation":"If the probe result has none of the recognized kinds (auth/http/exception/ok), verifyZsxqIdentity throws CommandExecutionError('Unexpected zsxq probe: ...') containing the JSON of the whole probe object. This is a defensive branch for malformed or unclassified probe outcomes — effectively an internal invariant violation.","triggerScenarios":"The page-injected probe script returns an object without a recognized 'kind' field, e.g. due to a version mismatch between the probe script and this dispatcher, or the script's return value being altered/undefined-shaped.","commonSituations":"Running mismatched library versions where the probe contract changed; browser serialization quirks stripping fields from the injected script's return value; custom patches to the probe code.","solutions":["Inspect the JSON dump in the message to see the actual probe shape.","Upgrade/downgrade the library so the probe script and dispatcher are from the same version.","Re-run the command — transient serialization failures in the browser context can produce empty results.","If reproducible, log page content and report the probe output as a bug to the library maintainers."],"exampleFix":"// before\nconst id = await verifyZsxqIdentity(page); // throws Unexpected probe\n// after\nlet id;\ntry { id = await verifyZsxqIdentity(page); }\ncatch (e) {\n  if (e.message.includes('Unexpected zsxq probe')) {\n    id = await verifyZsxqIdentity(await page.context().newPage()); // retry on a fresh page\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"const isUnexpectedProbe = (e) => (e?.message || '').includes('Unexpected zsxq probe:');","tryCatchPattern":"try {\n  return await verifyZsxqIdentity(page);\n} catch (e) {\n  if (isUnexpectedProbe(e)) {\n    const fresh = await page.context().newPage();\n    try { return await verifyZsxqIdentity(fresh); }\n    finally { await fresh.close(); }\n  }\n  throw e;\n}","preventionTips":["Keep the probe script and dispatcher on the same library version — avoid partial upgrades.","Don't monkey-patch or intercept the injected probe script's return value.","On occurrence, capture the JSON dump from the message for a bug report."],"tags":["internal","invariant","probe"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}