{"record":{"id":"c74c5cf1ac169be4","repo":"jackwener/OpenCLI","slug":"unexpected-wechat-channels-probe-json-stringify","errorCode":null,"errorMessage":"Unexpected WeChat Channels probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected WeChat Channels probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/wechat-channels/auth.js","lineNumber":45,"sourceCode":"      const d = await r.json();\n      if (!d || d.base_resp?.ret !== 0) {\n        return { kind: 'auth', detail: 'WeChat Channels auth_data base_resp.ret=' + String(d?.base_resp?.ret) };\n      }\n      const fu = d.data?.finder_user || d.finder_user || {};\n      const userId = String(fu.uniq_id || fu.username || '');\n      const name = String(fu.nickname || fu.name || '');\n      if (!userId && !name) {\n        return { kind: 'auth', detail: 'WeChat Channels auth_data 200 but finder_user empty' };\n      }\n      return { ok: true, user_id: userId, name };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('channels.weixin.qq.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from auth_data`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`WeChat Channels whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected WeChat Channels probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, name: probe.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'wechat-channels',\n  domain: 'channels.weixin.qq.com',\n  loginUrl: 'https://channels.weixin.qq.com/login.html?from=assistant',\n  columns: ['user_id', 'name'],\n  quickCheck: hasWechatChannelsSessionCookie,\n  verify: verifyWechatChannelsIdentity,\n  poll: async (page) => {\n    if (!await hasWechatChannelsSessionCookie(page)) {\n      throw new AuthRequiredError('channels.weixin.qq.com', 'Waiting for WeChat Channels sessionid cookie');\n    }\n    return verifyWechatChannelsIdentity(page);\n  },\n});\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wechat-channels/auth.js#L27-L63","documentation":"Final sanity check: if the probe result is none of the known kinds ('auth'/'http'/'exception') and lacks ok:true, the tool throws this CommandExecutionError embedding the raw probe object. This guards against unexpected probe shapes — including probe being null/undefined when page.evaluate returned nothing.","triggerScenarios":"page.evaluate returns null/undefined (page closed or navigated before the async IIFE resolved); a future/unknown probe response shape; the evaluate serialization dropped the result object.","commonSituations":"Slow page where the async probe hadn't resolved and the context tore down; automation framework returning undefined for pending promises; version mismatch between the probe script and expected result schema.","solutions":["Inspect the JSON in the message to see what the probe actually returned.","Retry — a torn-down evaluation context is often transient.","Ensure the platform page stays open and fully loaded during verification (avoid navigating away).","Update the CLI — the probe schema may have changed server-side and needs a newer probe script.","If it reproduces, capture the page state (URL, cookies) and file a bug with the probe JSON."],"exampleFix":"// before\nconst probe = await page.evaluate(`(async () => { ... })()`); // may return undefined\n// after\nconst probe = await page.evaluate(`(async () => { ... })()`);\nif (!probe) throw new CommandExecutionError('Probe did not return; page may have navigated — retry');","handlingStrategy":"try-catch","validationCode":"// Guard the raw probe yourself if calling internals:\nconst probe = await page.evaluate(probeScript);\nif (probe == null) throw new Error('Probe returned nothing — page navigated or closed; retry');","typeGuard":"function isKnownProbe(p) { return p != null && typeof p === 'object' && ('ok' in p || ['auth','http','exception'].includes(p.kind)); }","tryCatchPattern":"try {\n  const identity = await verifyWechatChannelsIdentity(page);\n} catch (e) {\n  if (/Unexpected WeChat Channels probe/.test(e.message)) {\n    console.error('Raw probe:', e.message); // capture for bug report\n    return verifyWechatChannelsIdentity(page); // single retry for torn-down contexts\n  }\n  throw e;\n}","preventionTips":["Keep the page open and idle during verification","Retry once — undefined probes usually mean a navigation race","Keep the CLI updated; server response schema may drift","Log the embedded probe JSON when filing bugs"],"tags":["wechat","probe","unexpected-state","serialization"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}