jackwener/OpenCLI · error · ArgumentError
xianyu messages requires item_id/user_id or --rank from xian
Error message
xianyu messages requires item_id/user_id or --rank from xianyu inbox
What it means
When neither --rank nor any targeting ID is provided (rank === 0, no item_id, no user_id), `xianyu messages` has no way to identify a conversation and throws ArgumentError at clis/xianyu/messages.js:43. The command deliberately does not guess a default conversation; the caller must specify one.
Source
Thrown at clis/xianyu/messages.js:43
args: [
{ name: 'item_id', positional: true, help: '闲鱼商品 item_id' },
{ name: 'user_id', positional: true, help: '聊一聊对方的 user_id / peerUserId' },
{ name: 'limit', type: 'int', default: DEFAULT_MESSAGE_LIMIT, help: 'Number of visible messages to return' },
{ name: 'rank', type: 'int', default: 0, help: 'Conversation rank from xianyu inbox; clicks the visible row instead of requiring IDs' },
],
columns: ['index', 'peer_name', 'item_title', 'message', 'item_id', 'peer_user_id', 'url'],
func: async (page, kwargs) => {
const hasItemId = kwargs.item_id != null && kwargs.item_id !== '';
const hasUserId = kwargs.user_id != null && kwargs.user_id !== '';
const rank = normalizeRank(kwargs.rank);
if (rank > 0 && (hasItemId || hasUserId)) {
throw new ArgumentError('xianyu messages accepts either item_id/user_id or --rank, not both');
}
if (rank === 0 && hasItemId !== hasUserId) {
throw new ArgumentError('xianyu messages requires both item_id and user_id, or --rank from xianyu inbox');
}
if (rank === 0 && !hasItemId && !hasUserId) {
throw new ArgumentError('xianyu messages requires item_id/user_id or --rank from xianyu inbox');
}
const hasIds = hasItemId && hasUserId;
const itemId = hasIds ? normalizeNumericId(kwargs.item_id, 'item_id', '1038951278192') : '';
const userId = hasIds ? normalizeNumericId(kwargs.user_id, 'user_id', '3650092411') : '';
const limit = normalizeLimit(kwargs.limit, DEFAULT_MESSAGE_LIMIT, MAX_MESSAGE_LIMIT, 'messages --limit');
let url = '';
if (hasIds) {
url = buildChatUrl(itemId, userId);
await page.goto(url);
} else {
if (!page.getCurrentUrl || !/https:\/\/www\.goofish\.com\/im\b/.test(await page.getCurrentUrl())) {
await page.goto('https://www.goofish.com/im');
}
}
await page.wait(2);
if (rank > 0) {
requireClickResult(await page.evaluate(buildClickInboxConversationEvaluate(rank - 1)), 'messages rank click');
await page.wait(2);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass --item_id and --user_id, or --rank N referencing a conversation from xianyu inbox output.
- Run `xianyu inbox` first to obtain ranked conversations, then call messages with --rank.
- Check that your caller isn't stripping or emptying kwargs (null and '' both count as missing).
- Add a pre-invocation check that at least one valid targeting mode is populated.
Example fix
// before await cli.run(['xianyu', 'messages']); // after const conv = (await cli.run(['xianyu', 'inbox']))[0]; await cli.run(['xianyu', 'messages', '--item_id', conv.item_id, '--user_id', conv.peer_user_id]);
Defensive patterns
Strategy: validation
Validate before calling
const hasTarget = rank > 0 || (itemId && userId);
if (!hasTarget) throw new Error('xianyu messages needs --rank or item_id+user_id'); Try / catch
try {
await runMessages(args);
} catch (e) {
if (e instanceof ArgumentError && /requires item_id\/user_id or --rank/.test(e.message)) {
console.error('No targeting specified — run `xianyu inbox` first, then pass --rank or IDs');
} else throw e;
} Prevention
- Always run xianyu inbox first in automated flows and thread rank/IDs through.
- Filter out null/empty kwargs before building the command line.
- Add a wrapper that defaults to inbox rank 1 when no target is given.
When it happens
Trigger: Running bare `xianyu messages` with no flags, or with flags whose values are null/empty strings so hasItemId/hasUserId evaluate false.
Common situations: Forgetting that messages requires explicit targeting (unlike `xianyu inbox`, which lists conversations); a wrapper dropping kwargs with empty values before exec; empty-string env/config variables feeding '' into the CLI.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- xianyu messages accepts either item_id/user_id or --rank, no
- xianyu messages requires both item_id and user_id, or --rank
- xianyu reply accepts either item_id/user_id or --rank, not b
- xianyu reply requires both item_id and user_id, or --rank fr
- xianyu reply requires item_id/user_id or --rank from xianyu
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/82ac54c70b65cf64.
Report an issue: GitHub.