jackwener/OpenCLI · error · CommandExecutionError
Xianyu search returned a malformed response
Error message
Xianyu search returned a malformed response
What it means
The CLI expects page.evaluate(buildSearchEvaluate(...)) to resolve to an object. If the evaluated script returns null, undefined, or a non-object (e.g. the page never produced a result), a CommandExecutionError ('malformed response') is thrown to fail fast instead of crashing on property access.
Source
Thrown at clis/xianyu/search.js:234
const province = String(kwargs.province || '').trim();
const city = String(kwargs.city || '').trim();
const searchFilter = buildSearchFilter(minPrice, maxPrice);
const extraFilterValue = buildExtraFilterValue(province, city);
const fromFilter = Boolean(searchFilter) || extraFilterValue !== '{}';
await page.goto(buildSearchUrl(query));
await page.wait(2);
const result = await page.evaluate(buildSearchEvaluate({ keyword: query, searchFilter, extraFilterValue, fromFilter, maxItems: limit }));
if (result?.error === 'auth-required') {
throw new AuthRequiredError('www.goofish.com', 'Xianyu search requires a logged-in browser session');
}
if (result?.error === 'blocked') {
throw new CommandExecutionError('Xianyu returned a verification page or blocked the current browser session');
}
if (result?.error === 'mtop-not-ready') {
throw selectorError('window.lib.mtop', '闲鱼页面未完成初始化,无法调用搜索接口');
}
if (!result || typeof result !== 'object') {
throw new CommandExecutionError('Xianyu search returned a malformed response');
}
const errorCode = String(result?.error_code || '');
const errorMessage = String(result?.error_message || '');
if (/FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED|FAIL_SYS_TOKEN/.test(errorCode) || /FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED/.test(errorMessage)) {
throw new AuthRequiredError('www.goofish.com', 'Xianyu search requires a logged-in browser session');
}
if (result?.error) {
throw new CommandExecutionError(errorMessage || `Xianyu search request failed: ${result.error}`);
}
if (!Array.isArray(result.items)) {
throw new CommandExecutionError('Xianyu search response did not include an items array');
}
const items = result.items;
if (!items.length) {
throw new EmptyResultError('xianyu search', '没有匹配的商品(筛选条件可能过窄,或当前关键词无结果)');
}
return items.map((item, index) => ({ rank: index + 1, ...item }));
},View on GitHub (pinned to 49907e53dc)
Solutions
- Retry the search; transient page-load issues often resolve on a second attempt
- Verify the goofish.com page loads correctly in the managed browser (no redirect/error page)
- Update the library if the site changed its page structure (check for a newer version)
Defensive patterns
Strategy: retry
Try / catch
try { await xianyuSearch(args); } catch (e) { if (e instanceof CommandExecutionError && /malformed response/.test(e.message)) { await wait(2000); return xianyuSearch(args); } throw e; } Prevention
- Avoid page navigation or concurrent tab activity during the search call
- Retry transient failures with a short backoff
- Keep the library updated against goofish.com page changes
When it happens
Trigger: buildSearchEvaluate's in-page promise rejects or resolves to null/undefined/non-object — e.g. the page navigated away or the evaluate wrapper swallowed an exception and returned nothing.
Common situations: Page navigations/timeouts mid-evaluation, evaluate serialization returning undefined, site DOM changes that abort the in-page script before it returns a result object.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Xianyu search requires a logged-in browser session
- ${label} failed: ${error?.message ?? error}
- ${config.site} login
- Failed to extract AIbase daily news: ${getErrorMessage(error
- antigravity cookies: document.cookie is empty.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c82cfd5b24e556cc.
Report an issue: GitHub.