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

  1. Retry the search; transient page-load issues often resolve on a second attempt
  2. Verify the goofish.com page loads correctly in the managed browser (no redirect/error page)
  3. 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

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

Related errors


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