{"record":{"id":"d7182814101360f1","repo":"jackwener/OpenCLI","slug":"weread-whoami-failed-result-detail","errorCode":null,"errorMessage":"WeRead whoami failed: ${result.detail}","messagePattern":"WeRead whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weread/auth.js","lineNumber":41,"sourceCode":"        return { kind: 'auth', detail: 'WeRead /web/user HTTP ' + res.status };\n      }\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});","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread/auth.js#L23-L59","documentation":"verifyWereadIdentity in clis/weread/auth.js throws CommandExecutionError when the in-page probe throws a JS exception — the evaluate body catches it and returns {kind:'exception', detail}, and the library re-raises it as `WeRead whoami failed: <detail>`. The identity probe never completed, so the failure is client-side inside the page context.","triggerScenarios":"Inside page.evaluate, document.cookie access, fetch('/web/user'), or res.json() throws — e.g. TypeError 'fetch is not defined' on older pages, network error, JSON parse failure of a non-JSON body, or CSP blocking the fetch.","commonSituations":"Browser page navigated away or closed mid-probe; page context lacking fetch; /web/user returning HTML that breaks res.json(); extension or CSP interfering; Chrome automation page detached.","solutions":["Read the detail suffix for the underlying exception (e.g. 'Failed to fetch' vs 'Unexpected token < in JSON').","Re-run the command — 'Failed to fetch' is often a transient network/navigation issue.","If the JSON parse fails, WeRead returned non-JSON — clear cookies and re-login at weread.qq.com.","Ensure the attached Chrome page stays open and is not redirected during verification; update Chrome if fetch is unavailable."],"exampleFix":"// before\nCommandExecutionError: WeRead whoami failed: Failed to fetch\n// after: keep weread.qq.com tab open/stable and retry, or re-login:\n$ opencli weread login && opencli weread whoami","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return await verifyWereadIdentity(page); } catch (e) {\n  if (/WeRead whoami failed/.test(e.message)) {\n    console.error('In-page probe threw:', e.message, '— keep the weread.qq.com tab open and retry.');\n  } else throw e;\n}","preventionTips":["Keep the weread.qq.com page stable (no navigation) during verification","Use a modern Chrome so fetch exists in the page context","Re-login if /web/user returns HTML instead of JSON","Retry once on transient 'Failed to fetch' before failing"],"tags":["javascript","browser","weread","whoami"],"backgroundTag":"browser-page-evaluation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}