{"record":{"id":"198c0619cf8102df","repo":"jackwener/OpenCLI","slug":"unexpected-doubao-probe-json-stringify-result","errorCode":null,"errorMessage":"Unexpected Doubao probe: ${JSON.stringify(result)}","messagePattern":"Unexpected Doubao probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/doubao/auth.js","lineNumber":39,"sourceCode":"      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      const data = d && d.data;\n      if (!data || !data.user_id_str) {\n        return { kind: 'auth', detail: 'Doubao /passport/account/info returned no user_id_str' };\n      }\n      return {\n        ok: true,\n        user_id: String(data.user_id_str),\n        name: String(data.name || data.screen_name || ''),\n      };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('www.doubao.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /passport/account/info`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Doubao whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Doubao probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'doubao',\n  domain: 'www.doubao.com',\n  loginUrl: 'https://www.doubao.com/chat/',\n  columns: ['user_id', 'name'],\n  verify: verifyDoubaoIdentity,\n  // passport_csrf_token is set for anonymous sessions too, so a cookie gate\n  // would navigate away mid-login. Probe the account API on the current page\n  // (no goto) and only confirm once a real user_id is present.\n  poll: async (page) => {\n    const loggedIn = await page.evaluate(`(async () => {\n      try {\n        const r = await fetch('/passport/account/info/v2/', { credentials: 'include', headers: { Accept: 'application/json' } });\n        if (!r.ok) return false;\n        const d = await r.json();","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/doubao/auth.js#L21-L57","documentation":"verifyDoubaoIdentity runs an in-page probe against Doubao's /passport/account/info endpoint and classifies the result as 'auth', 'http', or 'exception'. If the probe returns a result that is not ok and matches none of the known kinds, the function throws this CommandExecutionError as a catch-all. It indicates the in-page probe script returned an unexpected/unrecognized shape, so identity could not be verified.","triggerScenarios":"The page.evaluate probe returns {ok:false} or an object whose 'kind' is none of 'auth'|'http'|'exception', or result is null/undefined — e.g. Doubao changed the account-info response format, the probe script was interrupted, or an unknown result shape is produced.","commonSituations":"Doubao site DOM/API changes breaking the probe script; running against a redirected or partially loaded page; anti-bot interstitials altering the response; stale cookies producing unexpected payloads.","solutions":["Re-login to www.doubao.com so the account-info endpoint returns a recognizable response","Reload the Doubao tab and retry the command after the page fully loads","Check for Doubao verification/captcha challenges and complete them in the browser","Update the library to get probe-script fixes for the current Doubao site version"],"exampleFix":"// before\nif (!result?.ok) throw new CommandExecutionError(`Unexpected Doubao probe: ${JSON.stringify(result)}`);\n// after\nif (!result?.ok) {\n  if (result?.kind) throw new CommandExecutionError(`Doubao probe failed (${result.kind}): ${JSON.stringify(result)}`);\n  throw new CommandExecutionError('Unexpected Doubao probe: page returned no account info; try reloading or re-authenticating');\n}","handlingStrategy":"try-catch","validationCode":"const res = await page.evaluate(probeScript());\nif (!res || typeof res !== 'object' || !['auth','http','exception'].includes(res.kind)) {\n  throw new Error('Doubao probe returned unexpected shape: ' + JSON.stringify(res));\n}","typeGuard":"function isProbeResult(r) {\n  return !!r && typeof r === 'object' && ['auth','http','exception'].includes(r.kind) && typeof r.ok === 'boolean';\n}","tryCatchPattern":"try {\n  const identity = await verifyDoubaoIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) { await runLoginFlow(); }\n  else if (/Unexpected Doubao probe/.test(e.message)) { await page.reload(); await runLoginFlow(); }\n  else throw e;\n}","preventionTips":["Keep the Doubao tab fully loaded and free of overlays before probing","Re-authenticate when account-info responses look unfamiliar","Log the raw probe result on failure to spot site-format changes early","Update the library regularly to track Doubao site changes"],"tags":["doubao","auth","page-evaluate","unexpected-response"],"backgroundTag":"doubao-probe-unexpected-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}