jackwener/OpenCLI · error · CommandExecutionError

Weibo whoami returned malformed probe payload

Error message

Weibo whoami returned malformed probe payload

What it means

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.

Source

Thrown at clis/weibo/auth.js:51

}

async function verifyWeiboIdentity(page) {
  if (!await hasWeiboSessionCookie(page)) {
    throw new AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing');
  }
  await page.goto('https://weibo.com/');
  await page.wait(3);
  // getSelfUid throws AuthRequiredError when no logged-in uid can be resolved.
  const uid = await getSelfUid(page);
  if (typeof uid !== 'string' || !uid.trim()) {
    throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');
  }
  const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
  if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);
  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /ajax/profile/info`);
  if (result?.kind === 'exception') throw new CommandExecutionError(`Weibo whoami failed: ${result.detail}`);
  if (!result || Array.isArray(result) || typeof result !== 'object') {
    throw new CommandExecutionError('Weibo whoami returned malformed probe payload');
  }
  if (!result?.ok) throw new CommandExecutionError(`Unexpected Weibo probe: ${JSON.stringify(result)}`);
  if (!result.user_id) throw new CommandExecutionError('Weibo whoami returned no user id');
  return { user_id: result.user_id, screen_name: result.screen_name, profile_url: result.profile_url };
}

registerSiteAuthCommands({
  site: 'weibo',
  domain: 'weibo.com',
  loginUrl: 'https://weibo.com/login',
  columns: ['user_id', 'screen_name', 'profile_url'],
  quickCheck: hasWeiboSessionCookie,
  verify: verifyWeiboIdentity,
  poll: async (page) => {
    if (!await hasWeiboSessionCookie(page)) {
      throw new AuthRequiredError('weibo.com', 'Waiting for Weibo SUB / SUBP cookies');
    }
    return verifyWeiboIdentity(page);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure the page stays on weibo.com during login/verification — avoid navigating or restarting the browser mid-probe
  2. Retry the whoami once; transient navigation races often resolve on a second attempt
  3. Re-login to weibo.com; redirects to the login page can nullify the probe result
  4. Update the library if Weibo changed its page structure

Example fix

// before
const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
// after
await page.wait(2); // ensure no pending navigation
const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
Defensive patterns

Strategy: type-guard

Validate before calling

// probe result must be a plain object before use
if (!result || Array.isArray(result) || typeof result !== 'object') {
  throw new Error('probe returned malformed payload');
}

Type guard

function isPlainObject(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Try / catch

try {
  identity = await verifyWeiboIdentity(page);
} catch (err) {
  if (/malformed probe payload/.test(err.message)) {
    await page.wait(2);
    identity = await verifyWeiboIdentity(page); // navigation race: retry
  } else throw err;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/ac5ca81a732b6cad. Report an issue: GitHub.