jackwener/OpenCLI · error · CommandExecutionError

xiaohongshu ask returned a malformed page payload

Error message

xiaohongshu ask returned a malformed page payload

What it means

requireAskPayload throws this when the evaluate result from the ask page is not a non-null object. The library expects the injected script to return an object payload describing the ask exchange; anything else (null, undefined, a string) is treated as a malformed page payload. This usually means the page-side script failed silently or the page wasn't in the expected state.

Source

Thrown at clis/xiaohongshu/ask.js:379

}

function mapAskError(raw, timeoutSeconds) {
    const error = compactSingleLine(raw?.error);
    if (error === 'answer_timeout') {
        throw new TimeoutError('xiaohongshu ask', timeoutSeconds, '点点没有在超时时间内返回答案;可以重试或提高 --timeout。');
    }
    if (error === 'send_message_failed') {
        throw new AuthRequiredError(XHS_WEB_HOST, 'Xiaohongshu 点点 did not accept the query. Check login status for www.xiaohongshu.com.');
    }
    throw new CommandExecutionError(
        `xiaohongshu ask failed: ${error || 'unknown error'}`,
        raw?.page_url ? `Page URL: ${raw.page_url}` : undefined,
    );
}

function requireAskPayload(raw) {
    if (!raw || typeof raw !== 'object') {
        throw new CommandExecutionError('xiaohongshu ask returned a malformed page payload');
    }
    const answer = cleanText(raw.answer || raw.base_info?.text || '');
    if (!answer) {
        throw new CommandExecutionError('xiaohongshu ask returned a malformed page payload: missing answer');
    }
    if (!compactSingleLine(raw.message_id) || !compactSingleLine(raw.conversation_id)) {
        throw new CommandExecutionError('xiaohongshu ask returned a malformed page payload: missing message identity');
    }
}

export const command = cli({
    site: 'xiaohongshu',
    name: 'ask',
    access: 'write',
    description: 'Ask 小红书点点 and return the answer with citation sources.',
    domain: XHS_WEB_HOST,
    strategy: Strategy.COOKIE,
    browser: true,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run login and confirm www.xiaohongshu.com loads normally in the controlled browser.
  2. Retry the command — transient navigation/redirects can produce empty results.
  3. Update the library so buildAskEvaluateJs matches the current XHS page.
  4. Dump the raw page HTML at failure time to see what the script actually saw.
  5. Check whether XHS is showing a security verification page for your IP/account.

Example fix

// before
const raw = await page.evaluate(js); // may be null after XHS redesign
// after
const raw = await page.evaluate(js);
if (!raw || typeof raw !== 'object') {
  await page.screenshot({ path: 'xhs-ask-debug.png' }); // diagnose page state
  throw new Error('empty ask payload — see screenshot');
}
Defensive patterns

Strategy: type-guard

Type guard

function isAskPayload(v) {
  return v !== null && typeof v === 'object';
}
// use: if (!isAskPayload(raw)) handleMalformed();

Try / catch

try {
  const res = await xiaohongshuAsk({ query });
  return res;
} catch (e) {
  if (/malformed page payload/.test(e.message)) {
    await runXhsLogin();
    return xiaohongshuAsk({ query }); // retry once after re-auth
  }
  throw e;
}

Prevention

When it happens

Trigger: In the command handler, after unwrapEvaluateResult(await page.evaluate(buildAskEvaluateJs(...))), the value is null/undefined/a primitive, triggering the explicit !raw || typeof raw !== 'object' check.

Common situations: The XHS page structure changed so the injected script returns nothing; navigation/redirect landed on a login or CAPTCHA page; the script threw internally and the wrapper swallowed it into null; a very old library version against a new XHS front-end.

Understand the failure class

Related errors


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