jackwener/OpenCLI · error · CommandExecutionError

Weibo uid resolver returned a malformed uid

Error message

Weibo uid resolver returned a malformed uid

What it means

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.

Source

Thrown at clis/weibo/auth.js:44

        return { kind: 'auth', detail: 'Weibo /ajax/profile/info returned no user — anonymous' };
      }
      return { ok: true, user_id: String(user.id), screen_name: String(user.screen_name || ''), profile_url: String(user.profile_url || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };
    }
  })()`;
}

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'],

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log the raw getSelfUid output to see what is actually returned
  2. Update getSelfUid's selector/API parsing to match current weibo.com markup
  3. Coerce numeric uids with String(uid).trim() inside getSelfUid before returning
  4. Retry after a full page reload — partial loads can yield empty extraction

Example fix

// before
const uid = await getSelfUid(page);
if (typeof uid !== 'string' || !uid.trim()) {
  throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');
}
// after
const rawUid = await getSelfUid(page);
const uid = rawUid == null ? '' : String(rawUid).trim();
if (!/^\d+$/.test(uid)) {
  throw new CommandExecutionError(`Weibo uid resolver returned a malformed uid: ${JSON.stringify(rawUid)}`);
}
Defensive patterns

Strategy: type-guard

Validate before calling

const raw = await getSelfUid(page);
const uid = raw == null ? '' : String(raw).trim();
if (!/^\d+$/.test(uid)) throw new Error(`Cannot resolve Weibo uid: ${JSON.stringify(raw)}`);

Type guard

function isValidWeiboUid(u) {
  return typeof u === 'string' && /^\d{5,}$/.test(u.trim());
}

Try / catch

try {
  await verifyWeiboIdentity(page);
} catch (e) {
  if (/malformed uid/.test(e.message)) {
    console.error('Uid extraction failed — weibo.com markup may have changed; inspect the page.');
  } else throw e;
}

Prevention

When it happens

Trigger: getSelfUid returned null/undefined, a non-string (number, object), or an empty/blank string instead of a uid string.

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

Understand the failure class

Related errors


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