{"record":{"id":"287ce24f47981202","repo":"jackwener/OpenCLI","slug":"weibo-sub-subp-cookies-missing","errorCode":null,"errorMessage":"Weibo SUB / SUBP cookies missing","messagePattern":"Weibo SUB / SUBP cookies missing","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/weibo/auth.js","lineNumber":37,"sourceCode":"      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Weibo /ajax/profile/info HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      const user = d && d.data && d.data.user;\n      if (!user || !user.id) {\n        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 };","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/auth.js#L19-L55","documentation":"verifyWeiboIdentity first checks for Weibo's SUB/SUBP session cookies via hasWeiboSessionCookie. If they are absent, it throws AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing') because there is no logged-in session to verify identity against.","triggerScenarios":"hasWeiboSessionCookie(page) resolves false: cookies were never set, expired, cleared, or the page belongs to a different browser context/profile.","commonSituations":"Running against a fresh/incognito browser profile; Weibo invalidated old session cookies; cookies stored under a different domain variant (weibo.cn vs weibo.com); user logged out between commands.","solutions":["Log in to weibo.com in the controlled browser (or run the weibo login command) before publishing","Use a persistent session profile so cookies survive between runs","Check cookie names/domains in hasWeiboSessionCookie still match Weibo's current session cookies","Re-run after clearing corrupted cookie state and logging in fresh"],"exampleFix":"// before\nawait publish(page, opts); // page has no session\n// after\nconst auth = await checkWeiboAuth(page);\nif (!auth.ok) await runWeiboLogin(page); // sets SUB/SUBP cookies\nawait publish(page, opts);","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies?.() ?? [];\nconst hasSession = cookies.some(c => ['SUB','SUBP'].includes(c.name) && c.value);\nif (!hasSession) throw new Error('Log in to weibo.com first — SUB/SUBP cookies missing');","typeGuard":"function hasWeiboCookies(cookieList) {\n  return Array.isArray(cookieList) &&\n    ['SUB', 'SUBP'].every(name => cookieList.some(c => c.name === name && !!c.value));\n}","tryCatchPattern":"try {\n  await verifyWeiboIdentity(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError && /SUB \\/ SUBP/.test(e.message)) {\n    console.error('No Weibo session — run the login flow, then retry.');\n  } else throw e;\n}","preventionTips":["Log in to weibo.com before running publish commands","Use a persistent browser profile so cookies persist","Re-login when sessions expire rather than reusing stale profiles","Verify cookie presence cheaply before invoking the full flow"],"tags":["auth","cookies","weibo"],"backgroundTag":"missing-session-cookies","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}