{"record":{"id":"c7d17f1909e41a39","repo":"jackwener/OpenCLI","slug":"unexpected-weread-probe-json-stringify-result","errorCode":null,"errorMessage":"Unexpected WeRead probe: ${JSON.stringify(result)}","messagePattern":"Unexpected WeRead probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"warning","filePath":"clis/weread/auth.js","lineNumber":42,"sourceCode":"      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      if (d && d.errCode && d.errCode !== 0) {\n        return { kind: 'auth', detail: 'WeRead /web/user errCode=' + d.errCode };\n      }\n      return {\n        ok: true,\n        user_id: String(d.userVid || wrVid),\n        name: String(d.name || d.nickName || ''),\n      };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('weread.qq.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /web/user`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`WeRead whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected WeRead probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'weread',\n  domain: 'weread.qq.com',\n  loginUrl: 'https://weread.qq.com/',\n  columns: ['user_id', 'name'],\n  quickCheck: hasWereadSessionCookie,\n  verify: verifyWereadIdentity,\n  poll: async (page) => {\n    if (!await hasWereadSessionCookie(page)) {\n      throw new AuthRequiredError('weread.qq.com', 'Waiting for WeRead wr_vid cookie');\n    }\n    return verifyWereadIdentity(page);\n  },\n});\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread/auth.js#L24-L60","documentation":"verifyWereadIdentity in clis/weread/auth.js throws CommandExecutionError as a last-resort guard when the probe result has no recognized shape: kind is not 'auth'/'http'/'exception' and result.ok is falsy. It means the in-page script returned null/undefined or an unexpected object, so the library cannot classify the outcome.","triggerScenarios":"page.evaluate returns null or undefined (page navigated, evaluate deserialization issue), or returns an object without kind/ok (e.g. a WeRead script overwrote something, or the evaluate string was mangled), falling through all four kind checks to `!result?.ok`.","commonSituations":"The tab navigated away between page.goto and evaluate; an automation/driver version mismatch making evaluate return undefined; a redirect page (login wall) replacing the weread.qq.com context; older CLI evaluated against an incompatible page.","solutions":["Re-run the command — a transient navigation race often makes evaluate return undefined once.","Check the JSON.stringify(result) in the message to see what actually came back and adjust.","Re-login with `weread login` so page.goto lands on the real weread.qq.com page, not a redirect wall.","Update the CLI/automation driver if evaluate consistently returns null (environment/version mismatch)."],"exampleFix":"// before\nCommandExecutionError: Unexpected WeRead probe: null\n// after: retry after ensuring the weread.qq.com tab is on a stable page\n$ opencli weread login && opencli weread whoami","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isProbeResult(r) { return r !== null && typeof r === 'object' && (('kind' in r) || ('ok' in r)); }","tryCatchPattern":"try { return await verifyWereadIdentity(page); } catch (e) {\n  if (/Unexpected WeRead probe/.test(e.message)) {\n    console.error('Probe returned an unrecognized shape (page navigated?) — retry or re-login.');\n  } else throw e;\n}","preventionTips":["Avoid navigating the tab between page.goto and evaluate","Re-login so page.goto lands on the real site, not a redirect wall","Keep the CLI/automation driver up to date","Log the raw probe result (in the error message) when debugging"],"tags":["javascript","browser","weread","unexpected-state"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}