jackwener/OpenCLI · error · ArgumentError

${label} must be a numeric ID

Error message

${label} must be a numeric ID

What it means

normalizeNumericId validates that an ID argument (for sku, itemId, userId commands) is a string of digits only. Anything else — including numbers with signs, decimals, whitespace-plus-symbols, or alphanumeric IDs — raises an ArgumentError instructing the caller to pass a numeric ID with an example.

Source

Thrown at clis/xianyu/utils.js:5

import { ArgumentError } from '@jackwener/opencli/errors';
export function normalizeNumericId(value, label, example) {
    const normalized = String(value || '').trim();
    if (!/^\d+$/.test(normalized)) {
        throw new ArgumentError(`${label} must be a numeric ID`, `Pass a numeric ${label}, for example: ${example}`);
    }
    return normalized;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass only the digits of the ID, e.g. xianyu item 812345678901
  2. Extract the id query parameter from an item URL instead of pasting the whole URL
  3. Trim whitespace/control characters from the value before passing it
  4. Confirm you are not using a share token or short code in place of the numeric ID

Example fix

// before
xianyu item 'https://www.goofish.com/item?id=812345678901'
// after
xianyu item 812345678901
Defensive patterns

Strategy: validation

Validate before calling

function assertNumericId(v){ const s=String(v??'').trim(); if(!/^\d+$/.test(s)) throw new Error(`ID must be numeric digits, got: ${v}`); return s; }
const id = assertNumericId(rawId);

Type guard

const isNumericId = (v) => typeof v === 'string' || typeof v === 'number' ? /^\d+$/.test(String(v).trim()) : false;

Try / catch

try { await xianyuItem(id); } catch (e) { if (e instanceof ArgumentError && /must be a numeric ID/.test(e.message)) { const m = String(rawId).match(/[?&]id=(\d+)/); if (m) return xianyuItem(m[1]); } throw e; }

Prevention

When it happens

Trigger: Calling `xianyu sku` / `xianyu item` / `xianyu user` with a non-numeric ID such as 'abc123', '1.5', '-42', a full item URL pasted instead of the ID, or an empty/null value.

Common situations: Pasting a goofish.com item URL (https://www.goofish.com/item?id=123...) instead of extracting the id query param, copying an ID with trailing spaces/invisible characters, or confusing numeric item IDs with alphanumeric share codes.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3b3769535c8fc5b7. Report an issue: GitHub.