{"record":{"id":"38580be9bb5cf380","repo":"jackwener/OpenCLI","slug":"xianyu-reply-accepts-either-item-id-user-id-or-r","errorCode":null,"errorMessage":"xianyu reply accepts either item_id/user_id or --rank, not both","messagePattern":"xianyu reply accepts either item_id/user_id or --rank, not both","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/reply.js","lineNumber":27,"sourceCode":"    access: 'write',\n    description: '回复指定闲鱼私信会话',\n    domain: 'www.goofish.com',\n    strategy: Strategy.COOKIE,\n    navigateBefore: false,\n    browser: true,\n    args: [\n        { name: 'item_id', positional: true, help: '闲鱼商品 item_id' },\n        { name: 'user_id', positional: true, help: '聊一聊对方的 user_id / peerUserId' },\n        { name: 'text', required: true, help: 'Message text to send' },\n        { name: 'rank', type: 'int', default: 0, help: 'Conversation rank from xianyu inbox; clicks the visible row instead of requiring IDs' },\n    ],\n    columns: ['status', 'peer_name', 'item_title', 'price', 'location', 'message'],\n    func: async (page, kwargs) => {\n        const hasItemId = kwargs.item_id != null && kwargs.item_id !== '';\n        const hasUserId = kwargs.user_id != null && kwargs.user_id !== '';\n        const rank = normalizeRank(kwargs.rank);\n        if (rank > 0 && (hasItemId || hasUserId)) {\n            throw new ArgumentError('xianyu reply accepts either item_id/user_id or --rank, not both');\n        }\n        if (rank === 0 && hasItemId !== hasUserId) {\n            throw new ArgumentError('xianyu reply requires both item_id and user_id, or --rank from xianyu inbox');\n        }\n        if (rank === 0 && !hasItemId && !hasUserId) {\n            throw new ArgumentError('xianyu reply requires item_id/user_id or --rank from xianyu inbox');\n        }\n        const hasIds = hasItemId && hasUserId;\n        const itemId = hasIds ? normalizeNumericId(kwargs.item_id, 'item_id', '1038951278192') : '';\n        const userId = hasIds ? normalizeNumericId(kwargs.user_id, 'user_id', '3650092411') : '';\n        const text = requireText(kwargs.text, 'xianyu reply --text');\n        const url = hasIds ? buildChatUrl(itemId, userId) : '';\n        if (hasIds) {\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            }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/reply.js#L9-L45","documentation":"The xianyu reply command supports two mutually exclusive targeting modes: explicit item_id/user_id pair, or --rank (position of a conversation in the xianyu inbox). Passing --rank together with item_id and/or user_id is ambiguous and rejected with this ArgumentError during argument normalization at clis/xianyu/reply.js:26-28.","triggerScenarios":"Invoking `xianyu reply <item_id> <user_id> --text ... --rank 2` (or any --rank > 0 with either ID present). Condition: normalizeRank(kwargs.rank) > 0 && (hasItemId || hasUserId).","commonSituations":"Scripting a reply from a saved inbox rank but accidentally also passing positional IDs copied from a previous invocation; a wrapper template that always injects item_id/user_id while the user adds --rank.","solutions":["Remove --rank and rely on item_id + user_id, or drop the IDs and use only --rank.","If automating from inbox output, standardize on --rank exclusively and stop forwarding positional IDs."],"exampleFix":"// before (ambiguous)\nawait xianyuReply({ item_id: '1038951278192', user_id: '3650092411', rank: 2, text: 'hi' });\n// after: pick one mode\nawait xianyuReply({ rank: 2, text: 'hi' });","handlingStrategy":"validation","validationCode":"const idsGiven = Boolean(kwargs.item_id || kwargs.user_id);\nconst rankGiven = Number(kwargs.rank) > 0;\nif (idsGiven && rankGiven) throw new Error('Pass either item_id/user_id or --rank, not both.');","typeGuard":null,"tryCatchPattern":"try {\n  await reply(kwargs);\n} catch (e) {\n  if (String(e.message).includes('not both')) {\n    // prefer explicit IDs when both are present\n    const { rank, ...rest } = kwargs;\n    return reply(rest);\n  }\n  throw e;\n}","preventionTips":["Choose one targeting mode per invocation and stick to it in scripts.","Avoid wrapper templates that always inject item_id/user_id.","Validate the composed argv before invoking the CLI in automation."],"tags":["argument-validation","cli-usage","xianyu"],"backgroundTag":"conflicting-arguments","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}