{"record":{"id":"02d606cc522459fc","repo":"jackwener/OpenCLI","slug":"xiaohongshu-ask-failed-error-unknown-error","errorCode":null,"errorMessage":"xiaohongshu ask failed: ${error || 'unknown error'}","messagePattern":"xiaohongshu ask failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/ask.js","lineNumber":371,"sourceCode":"      })()\n    `;\n}\n\nfunction requirePrompt(query) {\n    const prompt = String(query || '').trim();\n    if (!prompt) throw new ArgumentError('query is required');\n    return prompt;\n}\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","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/ask.js#L353-L389","documentation":"This is the catch-all CommandExecutionError from mapAskError: the ask page script returned an error value that is neither 'answer_timeout' nor 'send_message_failed', so the library wraps it into 'xiaohongshu ask failed: <error>' with the page URL as a hint. It signals an unrecognized failure mode of the in-page ask flow.","triggerScenarios":"raw.error is any falsy/unexpected value (e.g. undefined, 'unknown', a new XHS error code) and raw.ok === false causes mapAskError to fall through to the final throw.","commonSituations":"Xiaohongshu changed its front-end error codes after an update; the page returned an unexpected response shape; a transient network hiccup produced an unmapped error; a bug in the injected script yields no error field.","solutions":["Read the interpolated error string (and Page URL hint) to identify the actual failure cause.","Retry the ask command — transient page issues often resolve.","Re-run login to rule out session problems even though it wasn't classified as auth failure.","Update the library if XHS changed its page behavior/error vocabulary.","Inspect raw.page_url in the browser to see what state the page was in."],"exampleFix":"// before\nconst res = await xiaohongshuAsk({ query });\n// after\ntry {\n  const res = await xiaohongshuAsk({ query });\n} catch (e) {\n  console.error('ask failed:', e.message); // includes unmapped XHS error\n  await xiaohongshuLogin();\n  return xiaohongshuAsk({ query });\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await xiaohongshuAsk({ query });\n} catch (e) {\n  if (/xiaohongshu ask failed:/.test(e.message) && attempts < 3) {\n    await sleep(2000 * attempts);\n    return xiaohongshuAsk({ query });\n  }\n  throw e;\n}","preventionTips":["Keep the library updated since XHS error codes can change without notice.","Log the full unmapped error text and page_url for diagnosis.","Retry transient failures with backoff before surfacing to users.","Verify session health even for non-auth-classified failures."],"tags":["xiaohongshu","automation","unmapped-error","page-scraping"],"backgroundTag":"unmapped-remote-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}