{"record":{"id":"ac5ca81a732b6cad","repo":"jackwener/OpenCLI","slug":"weibo-whoami-returned-malformed-probe-payload","errorCode":null,"errorMessage":"Weibo whoami returned malformed probe payload","messagePattern":"Weibo whoami returned malformed probe payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weibo/auth.js","lineNumber":51,"sourceCode":"}\n\nasync function verifyWeiboIdentity(page) {\n  if (!await hasWeiboSessionCookie(page)) {\n    throw new AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing');\n  }\n  await page.goto('https://weibo.com/');\n  await page.wait(3);\n  // getSelfUid throws AuthRequiredError when no logged-in uid can be resolved.\n  const uid = await getSelfUid(page);\n  if (typeof uid !== 'string' || !uid.trim()) {\n    throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');\n  }\n  const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));\n  if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /ajax/profile/info`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Weibo whoami failed: ${result.detail}`);\n  if (!result || Array.isArray(result) || typeof result !== 'object') {\n    throw new CommandExecutionError('Weibo whoami returned malformed probe payload');\n  }\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Weibo probe: ${JSON.stringify(result)}`);\n  if (!result.user_id) throw new CommandExecutionError('Weibo whoami returned no user id');\n  return { user_id: result.user_id, screen_name: result.screen_name, profile_url: result.profile_url };\n}\n\nregisterSiteAuthCommands({\n  site: 'weibo',\n  domain: 'weibo.com',\n  loginUrl: 'https://weibo.com/login',\n  columns: ['user_id', 'screen_name', 'profile_url'],\n  quickCheck: hasWeiboSessionCookie,\n  verify: verifyWeiboIdentity,\n  poll: async (page) => {\n    if (!await hasWeiboSessionCookie(page)) {\n      throw new AuthRequiredError('weibo.com', 'Waiting for Weibo SUB / SUBP cookies');\n    }\n    return verifyWeiboIdentity(page);","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/auth.js#L33-L69","documentation":"After the probe returns, verifyWeiboIdentity validates the shape of the result object. If result is null, an array, or not a plain object, the payload cannot be interpreted at all, so the library throws this CommandExecutionError. It guards against unwrapEvaluateResult passing through something the probe never produced.","triggerScenarios":"page.evaluate resolves to null/undefined, an array, or a non-object (e.g. the injected probe string/script was replaced or truncated, or the browser context navigated mid-evaluate so the evaluation returned nothing usable).","commonSituations":"Navigation away from weibo.com during the probe (redirects to passport/login), a proxy or extension stripping the injected script result, or a library/Weibo change altering what buildWeiboIdentityProbe returns.","solutions":["Ensure the page stays on weibo.com during login/verification — avoid navigating or restarting the browser mid-probe","Retry the whoami once; transient navigation races often resolve on a second attempt","Re-login to weibo.com; redirects to the login page can nullify the probe result","Update the library if Weibo changed its page structure"],"exampleFix":"// before\nconst result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));\n// after\nawait page.wait(2); // ensure no pending navigation\nconst result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));","handlingStrategy":"type-guard","validationCode":"// probe result must be a plain object before use\nif (!result || Array.isArray(result) || typeof result !== 'object') {\n  throw new Error('probe returned malformed payload');\n}","typeGuard":"function isPlainObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  identity = await verifyWeiboIdentity(page);\n} catch (err) {\n  if (/malformed probe payload/.test(err.message)) {\n    await page.wait(2);\n    identity = await verifyWeiboIdentity(page); // navigation race: retry\n  } else throw err;\n}","preventionTips":["Don't navigate or close the tab while whoami/verification is in flight","Call whoami only after the page reports it is loaded and idle","Reuse the same browser context for login and verification","Retry once on this specific message before failing the flow"],"tags":["weibo","browser-automation","payload-validation"],"backgroundTag":"malformed-probe-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}