{"record":{"id":"c82cfd5b24e556cc","repo":"jackwener/OpenCLI","slug":"xianyu-search-returned-a-malformed-response","errorCode":null,"errorMessage":"Xianyu search returned a malformed response","messagePattern":"Xianyu search returned a malformed response","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/search.js","lineNumber":234,"sourceCode":"        const province = String(kwargs.province || '').trim();\n        const city = String(kwargs.city || '').trim();\n        const searchFilter = buildSearchFilter(minPrice, maxPrice);\n        const extraFilterValue = buildExtraFilterValue(province, city);\n        const fromFilter = Boolean(searchFilter) || extraFilterValue !== '{}';\n        await page.goto(buildSearchUrl(query));\n        await page.wait(2);\n        const result = await page.evaluate(buildSearchEvaluate({ keyword: query, searchFilter, extraFilterValue, fromFilter, maxItems: limit }));\n        if (result?.error === 'auth-required') {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu search requires a logged-in browser session');\n        }\n        if (result?.error === 'blocked') {\n            throw new CommandExecutionError('Xianyu returned a verification page or blocked the current browser session');\n        }\n        if (result?.error === 'mtop-not-ready') {\n            throw selectorError('window.lib.mtop', '闲鱼页面未完成初始化，无法调用搜索接口');\n        }\n        if (!result || typeof result !== 'object') {\n            throw new CommandExecutionError('Xianyu search returned a malformed response');\n        }\n        const errorCode = String(result?.error_code || '');\n        const errorMessage = String(result?.error_message || '');\n        if (/FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED|FAIL_SYS_TOKEN/.test(errorCode) || /FAIL_SYS_SESSION_EXPIRED|SESSION_EXPIRED/.test(errorMessage)) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu search requires a logged-in browser session');\n        }\n        if (result?.error) {\n            throw new CommandExecutionError(errorMessage || `Xianyu search request failed: ${result.error}`);\n        }\n        if (!Array.isArray(result.items)) {\n            throw new CommandExecutionError('Xianyu search response did not include an items array');\n        }\n        const items = result.items;\n        if (!items.length) {\n            throw new EmptyResultError('xianyu search', '没有匹配的商品（筛选条件可能过窄，或当前关键词无结果）');\n        }\n        return items.map((item, index) => ({ rank: index + 1, ...item }));\n    },","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/search.js#L216-L252","documentation":"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.","triggerScenarios":"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.","commonSituations":"Page navigations/timeouts mid-evaluation, evaluate serialization returning undefined, site DOM changes that abort the in-page script before it returns a result object.","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)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await xianyuSearch(args); } catch (e) { if (e instanceof CommandExecutionError && /malformed response/.test(e.message)) { await wait(2000); return xianyuSearch(args); } throw e; }","preventionTips":["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"],"tags":["malformed-response","browser","xianyu"],"backgroundTag":"malformed-api-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}