{"record":{"id":"a4f31a45ab2e000c","repo":"jackwener/OpenCLI","slug":"xianyu-messages-returned-malformed-message-list","errorCode":null,"errorMessage":"Xianyu messages returned malformed message list","messagePattern":"Xianyu messages returned malformed message list","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/messages.js","lineNumber":68,"sourceCode":"        if (hasIds) {\n            url = buildChatUrl(itemId, userId);\n            await page.goto(url);\n        } else {\n            if (!page.getCurrentUrl || !/https:\\/\\/www\\.goofish\\.com\\/im\\b/.test(await page.getCurrentUrl())) {\n                await page.goto('https://www.goofish.com/im');\n            }\n        }\n        await page.wait(2);\n        if (rank > 0) {\n            requireClickResult(await page.evaluate(buildClickInboxConversationEvaluate(rank - 1)), 'messages rank click');\n            await page.wait(2);\n        }\n        const state = requireEvaluateObject(await page.evaluate(buildExtractChatStateEvaluate(limit)), 'messages');\n        if (state?.requiresAuth) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu messages requires a logged-in browser session');\n        }\n        if (!Array.isArray(state.messages)) {\n            throw new CommandExecutionError('Xianyu messages returned malformed message list');\n        }\n        const messages = state.messages;\n        if (!messages.length) {\n            throw new EmptyResultError('xianyu messages', 'No visible messages were found in this Xianyu conversation');\n        }\n        return messages.slice(-limit).map((message, index) => ({\n            index: index + 1,\n            peer_name: state.peer_name || '',\n            item_title: state.item_title || '',\n            message: message.text || '',\n            item_id: itemId,\n            peer_user_id: userId,\n            url: url || '',\n        }));\n    },\n});\n\nexport const __test__ = {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/messages.js#L50-L86","documentation":"After in-page extraction, the CLI expects state.messages to be an array. If the evaluated object comes back without a messages array (page structure changed, extraction partially failed, or a non-standard page state was captured), CommandExecutionError('Xianyu messages returned malformed message list') is thrown at clis/xianyu/messages.js:68. This is a defensive check against malformed automation output, not an API business error.","triggerScenarios":"The buildExtractChatStateEvaluate script runs on a page whose DOM does not match expectations — e.g. an interstitial, a chat page still loading, a page variant after a Goofish front-end update, or the evaluate returning an object lacking the messages key.","commonSituations":"Goofish shipped a DOM/UI change that broke the extraction selectors; hitting a non-chat page because rank/index targeting landed on the wrong conversation; slow page load so state was captured mid-render; library version drift between CLI and site markup.","solutions":["Re-run the command once — a slow/mid-render page is the most frequent benign cause.","Update the CLI/library to the latest version, since Goofish DOM changes are usually patched upstream.","Verify the target conversation opens normally in the browser (not a captcha or error page).","Increase wait time before extraction so the chat fully renders.","Inspect the saved page state/screenshot; if the DOM changed, report or patch the extraction script."],"exampleFix":"// before: one malformed page aborts a batch sync\nfor (const c of convs) await fetchMessages(c);\n\n// after\nfor (const c of convs) {\n  try { await fetchMessages(c); }\n  catch (e) {\n    if (e instanceof CommandExecutionError && /malformed/.test(e.message)) { failures.push(c); continue; }\n    throw e;\n  }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isWellFormedChatState(s) { return s != null && typeof s === 'object' && Array.isArray(s.messages); }","tryCatchPattern":"let last;\nfor (let i = 0; i < 3; i++) {\n  try { return await fetchMessages(target); }\n  catch (e) { last = e; if (e instanceof CommandExecutionError) { await sleep(2000 * (i + 1)); continue; } throw e; }\n}\nthrow last;","preventionTips":["Keep the CLI updated — Goofish DOM changes break extraction selectors.","Wait for the chat to fully render before extraction.","Verify targeted conversations open normally (no captcha/interstitial).","Capture a screenshot/page dump on failure for diagnosis."],"tags":["browser-automation","dom-extraction","xianyu","scraping"],"backgroundTag":"page-structure-changed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}