{"record":{"id":"78499d2a98b27da3","repo":"jackwener/OpenCLI","slug":"nowcoder-whoami-failed-probe-detail","errorCode":null,"errorMessage":"Nowcoder whoami failed: ${probe.detail}","messagePattern":"Nowcoder whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/auth.js","lineNumber":48,"sourceCode":"    if (!d || !d.success || !d.data || !d.data.id) {\n      return { kind: 'auth', detail: 'nowcoder profile returned no user data (anonymous)' };\n    }\n    return { ok: true, user_id: String(d.data.id), nickname: String(d.data.nickname || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyNowcoderIdentity(page) {\n  if (!await hasNowcoderSessionCookie(page)) {\n    throw new AuthRequiredError('nowcoder.com', 'Nowcoder t cookie missing (anonymous)');\n  }\n  await page.goto('https://www.nowcoder.com/');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('nowcoder.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from nowcoder profile API`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Nowcoder whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected nowcoder probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, nickname: probe.nickname };\n}\n\nregisterSiteAuthCommands({\n  site: 'nowcoder',\n  domain: 'nowcoder.com',\n  loginUrl: 'https://www.nowcoder.com/login',\n  columns: ['user_id', 'nickname'],\n  verify: verifyNowcoderIdentity,\n  poll: async (page) => {\n    if (!await hasNowcoderSessionCookie(page)) {\n      throw new AuthRequiredError('nowcoder.com', 'Waiting for Nowcoder login');\n    }\n    return verifyNowcoderIdentity(page);\n  },\n});\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/auth.js#L30-L66","documentation":"The WHOAMI_PROBE runs inside the page inside a try/catch; any in-page exception (fetch failure, JSON parse error, script error) is converted to {kind:'exception', detail}. verifyNowcoderIdentity rethrows it as CommandExecutionError 'Nowcoder whoami failed: <detail>'. It indicates the verification script itself failed to execute or reach the API, not an auth rejection.","triggerScenarios":"Network failure from the browser to gw-c.nowcoder.com; page.evaluate failing because navigation didn't finish; r.json() throwing on non-JSON (e.g. HTML error page); CSP or extension interference with evaluate.","commonSituations":"Offline/proxied environments blocking gw-c.nowcoder.com; nowcoder serving an HTML maintenance page; page.wait(2) insufficient on slow loads leaving an incomplete DOM; browser closed mid-command.","solutions":["Read the interpolated detail to identify the underlying exception","Re-run after confirming network connectivity to nowcoder.com and gw-c.nowcoder.com","Increase wait time / ensure the homepage fully loads before evaluating","If r.json() got non-JSON, inspect the response content and adapt the probe"],"exampleFix":"// before\nconst who = await verifyNowcoderIdentity(page);\n// after\ntry {\n  const who = await verifyNowcoderIdentity(page);\n} catch (e) {\n  if (/Nowcoder whoami failed: /.test(e.message)) {\n    console.error('probe exception, retrying...', e.message);\n    await new Promise(r => setTimeout(r, 3000));\n    return verifyNowcoderIdentity(page);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Ensure network reachability and a loaded page before evaluating the probe:\nawait page.goto('https://www.nowcoder.com/', { waitUntil: 'domcontentloaded' });\nawait page.wait(2);","typeGuard":"function isExceptionProbe(p) { return p?.kind === 'exception' && typeof p.detail === 'string'; }","tryCatchPattern":"try {\n  return await verifyNowcoderIdentity(page);\n} catch (e) {\n  if (/Nowcoder whoami failed: /.test(e.message)) {\n    await new Promise(r => setTimeout(r, 3000));\n    return verifyNowcoderIdentity(page); // one retry for transient in-page failures\n  }\n  throw e;\n}","preventionTips":["Check outbound connectivity to gw-c.nowcoder.com from your environment","Allow enough page load/wait time before page.evaluate","Log the interpolated detail — it names the underlying in-page exception","Beware proxies/VPN/anti-bot tooling that break in-page fetches"],"tags":["network","page-evaluate","in-page-exception","nowcoder"],"backgroundTag":"in-page-script-exception","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}