{"record":{"id":"6ecb86c297fc99cd","repo":"jackwener/OpenCLI","slug":"weibo-uid-resolver-returned-a-malformed-uid","errorCode":null,"errorMessage":"Weibo uid resolver returned a malformed uid","messagePattern":"Weibo uid resolver returned a malformed uid","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/weibo/auth.js","lineNumber":44,"sourceCode":"        return { kind: 'auth', detail: 'Weibo /ajax/profile/info returned no user — anonymous' };\n      }\n      return { ok: true, user_id: String(user.id), screen_name: String(user.screen_name || ''), profile_url: String(user.profile_url || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`;\n}\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'],","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/auth.js#L26-L62","documentation":"After confirming cookies exist, verifyWeiboIdentity calls getSelfUid(page) to resolve the logged-in user's uid. If the resolver returns a non-string or empty/whitespace value, the command throws CommandExecutionError('Weibo uid resolver returned a malformed uid'). getSelfUid itself throws AuthRequiredError when no uid can be resolved, so this error means it returned something but not a usable uid.","triggerScenarios":"getSelfUid returned null/undefined, a non-string (number, object), or an empty/blank string instead of a uid string.","commonSituations":"Weibo changed the DOM/API the resolver scrapes so it now extracts an unexpected type; a partial page load left the uid element empty; resolver returning numeric uid where code expects string.","solutions":["Log the raw getSelfUid output to see what is actually returned","Update getSelfUid's selector/API parsing to match current weibo.com markup","Coerce numeric uids with String(uid).trim() inside getSelfUid before returning","Retry after a full page reload — partial loads can yield empty extraction"],"exampleFix":"// before\nconst uid = await getSelfUid(page);\nif (typeof uid !== 'string' || !uid.trim()) {\n  throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');\n}\n// after\nconst rawUid = await getSelfUid(page);\nconst uid = rawUid == null ? '' : String(rawUid).trim();\nif (!/^\\d+$/.test(uid)) {\n  throw new CommandExecutionError(`Weibo uid resolver returned a malformed uid: ${JSON.stringify(rawUid)}`);\n}","handlingStrategy":"type-guard","validationCode":"const raw = await getSelfUid(page);\nconst uid = raw == null ? '' : String(raw).trim();\nif (!/^\\d+$/.test(uid)) throw new Error(`Cannot resolve Weibo uid: ${JSON.stringify(raw)}`);","typeGuard":"function isValidWeiboUid(u) {\n  return typeof u === 'string' && /^\\d{5,}$/.test(u.trim());\n}","tryCatchPattern":"try {\n  await verifyWeiboIdentity(page);\n} catch (e) {\n  if (/malformed uid/.test(e.message)) {\n    console.error('Uid extraction failed — weibo.com markup may have changed; inspect the page.');\n  } else throw e;\n}","preventionTips":["Validate uid shape (numeric string) before using it","Update getSelfUid selectors when weibo.com changes markup","Coerce numeric returns to strings inside the resolver","Retry once after a full page reload to rule out partial loads"],"tags":["weibo","identity","parsing"],"backgroundTag":"malformed-uid-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}