{"record":{"id":"059f42894c3aef4f","repo":"jackwener/OpenCLI","slug":"xiaohongshu-ask-returned-a-malformed-page-payload","errorCode":null,"errorMessage":"xiaohongshu ask returned a malformed page payload","messagePattern":"xiaohongshu ask returned a malformed page payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/ask.js","lineNumber":379,"sourceCode":"}\n\nfunction mapAskError(raw, timeoutSeconds) {\n    const error = compactSingleLine(raw?.error);\n    if (error === 'answer_timeout') {\n        throw new TimeoutError('xiaohongshu ask', timeoutSeconds, '点点没有在超时时间内返回答案；可以重试或提高 --timeout。');\n    }\n    if (error === 'send_message_failed') {\n        throw new AuthRequiredError(XHS_WEB_HOST, 'Xiaohongshu 点点 did not accept the query. Check login status for www.xiaohongshu.com.');\n    }\n    throw new CommandExecutionError(\n        `xiaohongshu ask failed: ${error || 'unknown error'}`,\n        raw?.page_url ? `Page URL: ${raw.page_url}` : undefined,\n    );\n}\n\nfunction requireAskPayload(raw) {\n    if (!raw || typeof raw !== 'object') {\n        throw new CommandExecutionError('xiaohongshu ask returned a malformed page payload');\n    }\n    const answer = cleanText(raw.answer || raw.base_info?.text || '');\n    if (!answer) {\n        throw new CommandExecutionError('xiaohongshu ask returned a malformed page payload: missing answer');\n    }\n    if (!compactSingleLine(raw.message_id) || !compactSingleLine(raw.conversation_id)) {\n        throw new CommandExecutionError('xiaohongshu ask returned a malformed page payload: missing message identity');\n    }\n}\n\nexport const command = cli({\n    site: 'xiaohongshu',\n    name: 'ask',\n    access: 'write',\n    description: 'Ask 小红书点点 and return the answer with citation sources.',\n    domain: XHS_WEB_HOST,\n    strategy: Strategy.COOKIE,\n    browser: true,","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/ask.js#L361-L397","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run login and confirm www.xiaohongshu.com loads normally in the controlled browser.","Retry the command — transient navigation/redirects can produce empty results.","Update the library so buildAskEvaluateJs matches the current XHS page.","Dump the raw page HTML at failure time to see what the script actually saw.","Check whether XHS is showing a security verification page for your IP/account."],"exampleFix":"// before\nconst raw = await page.evaluate(js); // may be null after XHS redesign\n// after\nconst raw = await page.evaluate(js);\nif (!raw || typeof raw !== 'object') {\n  await page.screenshot({ path: 'xhs-ask-debug.png' }); // diagnose page state\n  throw new Error('empty ask payload — see screenshot');\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isAskPayload(v) {\n  return v !== null && typeof v === 'object';\n}\n// use: if (!isAskPayload(raw)) handleMalformed();","tryCatchPattern":"try {\n  const res = await xiaohongshuAsk({ query });\n  return res;\n} catch (e) {\n  if (/malformed page payload/.test(e.message)) {\n    await runXhsLogin();\n    return xiaohongshuAsk({ query }); // retry once after re-auth\n  }\n  throw e;\n}","preventionTips":["Increase --timeout so the page finishes loading before evaluate runs.","Capture screenshots/HTML on failure to detect login/CAPTCHA redirects.","Update the library when XHS redesigns its front-end.","Check for security-verification pages when this recurs."],"tags":["xiaohongshu","page-scraping","malformed-payload","automation"],"backgroundTag":"malformed-scrape-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}