{"record":{"id":"2739c4ae3e0d89e3","repo":"jackwener/OpenCLI","slug":"xianyu-messages-requires-both-item-id-and-user-id","errorCode":null,"errorMessage":"xianyu messages requires both item_id and user_id, or --rank from xianyu inbox","messagePattern":"xianyu messages requires both item_id and user_id, or --rank from xianyu inbox","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/messages.js","lineNumber":40,"sourceCode":"    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: 'limit', type: 'int', default: DEFAULT_MESSAGE_LIMIT, help: 'Number of visible messages to return' },\n        { name: 'rank', type: 'int', default: 0, help: 'Conversation rank from xianyu inbox; clicks the visible row instead of requiring IDs' },\n    ],\n    columns: ['index', 'peer_name', 'item_title', 'message', 'item_id', 'peer_user_id', 'url'],\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 messages accepts either item_id/user_id or --rank, not both');\n        }\n        if (rank === 0 && hasItemId !== hasUserId) {\n            throw new ArgumentError('xianyu messages requires both item_id and user_id, or --rank from xianyu inbox');\n        }\n        if (rank === 0 && !hasItemId && !hasUserId) {\n            throw new ArgumentError('xianyu messages 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 limit = normalizeLimit(kwargs.limit, DEFAULT_MESSAGE_LIMIT, MAX_MESSAGE_LIMIT, 'messages --limit');\n        let url = '';\n        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);","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/messages.js#L22-L58","documentation":"`xianyu messages` requires a complete targeting spec when not using --rank: item_id and user_id must be supplied together. When exactly one of the two is present (hasItemId !== hasUserId) and rank is 0, ArgumentError is thrown at clis/xianyu/messages.js:40. The conversation is keyed by the (item_id, user_id) pair, so one half alone cannot identify a chat.","triggerScenarios":"Running `xianyu messages --item_id 123` without --user_id, or `xianyu messages --user_id 456` without --item_id, with no (or a zero) --rank value.","commonSituations":"Partial data from an upstream system — e.g. only the item id was recorded and the counterparty user id was lost; one flag accidentally commented out or failing an emptiness check in generated CLI calls; confusing item_id with user_id and passing the same value twice under one flag name.","solutions":["Supply both --item_id and --user_id together (IDs are available from xianyu inbox / xianyu messages output).","Alternatively use --rank N to select the Nth conversation from the most recent xianyu inbox run.","Check for empty strings: kwargs with value '' count as absent, so `--item_id 123 --user_id \"\"` triggers this — fix the caller's data.","Validate the pair exists in your data source before invoking the command."],"exampleFix":"// before\nawait cli.run(['xianyu', 'messages', '--item_id', conv.itemId]);\n\n// after\nif (!conv.userId) throw new Error('cannot fetch messages without user_id');\nawait cli.run(['xianyu', 'messages', '--item_id', conv.itemId, '--user_id', conv.userId]);","handlingStrategy":"validation","validationCode":"if (!rank && (!itemId || !userId)) throw new Error('messages needs both item_id and user_id, or --rank');","typeGuard":null,"tryCatchPattern":"try {\n  await cli.run(['xianyu', 'messages', '--item_id', itemId, '--user_id', userId]);\n} catch (e) {\n  if (e instanceof ArgumentError && /requires both item_id and user_id/.test(e.message)) {\n    const conv = await inboxLookup(itemId); // resolve missing user_id upstream\n    return retryWithUserId(conv.peer_user_id);\n  }\n  throw e;\n}","preventionTips":["Store item_id and user_id together in your conversation records.","Check for empty-string values — they count as missing.","Resolve missing half of the pair from xianyu inbox before calling."],"tags":["argument-validation","cli-usage","xianyu"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}