jackwener/OpenCLI · error · ArgumentError

${label} must be a numeric Coupang product ID

Error message

${label} must be a numeric Coupang product ID

What it means

requireProductIdArg validates the --product-id argument: after handling the --url branch, it requires the value to be a purely numeric string of at least 6 digits (Coupang product IDs). Anything else (letters, spaces, short numbers, embedded IDs) throws this ArgumentError so callers get a typed failure instead of a bogus network request.

Source

Thrown at clis/coupang/utils.js:116

}
export function requireProductIdArg(raw, label = '--product-id') {
    const text = asString(raw);
    if (label === '--url') {
        try {
            const url = new URL(text.startsWith('http') ? text : `https://www.coupang.com${text}`);
            const match = url.pathname.match(/^\/vp\/products\/(\d{6,})(?:\/|$)/);
            const isCoupangHost = url.hostname === 'coupang.com' || url.hostname.endsWith('.coupang.com');
            if (isCoupangHost && match) {
                return match[1];
            }
        }
        catch {
            // Fall through to the typed validation error below.
        }
        throw new ArgumentError(`${label} must be a Coupang product URL containing /vp/products/<id>`);
    }
    if (!/^\d{6,}$/.test(text)) {
        throw new ArgumentError(`${label} must be a numeric Coupang product ID`);
    }
    return text;
}
export function canonicalizeProductUrl(rawUrl, productId) {
    const raw = asString(rawUrl);
    if (raw) {
        try {
            const url = new URL(raw.startsWith('http') ? raw : `https://www.coupang.com${raw}`);
            if (!url.hostname.includes('coupang.com'))
                return '';
            const id = normalizeProductId(url.pathname) || normalizeProductId(productId);
            if (!id)
                return url.toString();
            return `https://www.coupang.com/vp/products/${id}`;
        }
        catch {
            return '';
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass only the numeric product ID (6+ digits), e.g. --product-id 1234567890.
  2. If you have a URL, either use the --url flag (which parses /vp/products/<id>) or extract the ID with normalizeProductId() first.
  3. Pre-validate with /^\d{6,}$/ before calling the API.
  4. Check that the value is not an option-prefixed or quoted-empty string in your shell invocation.

Example fix

// before
await cli.coupang.product({ productId: 'https://www.coupang.com/vp/products/81543202' });
// after
await cli.coupang.product({ productId: '81543202' });
Defensive patterns

Strategy: validation

Validate before calling

function requireNumericProductId(v) {
  const s = String(v ?? '').trim();
  if (!/^\d{6,}$/.test(s)) throw new Error(`--product-id must be 6+ digits, got: ${v}`);
  return s;
}
const productId = requireNumericProductId(rawProductId);

Type guard

function isNumericProductId(v) {
  return typeof v === 'string' && /^\d{6,}$/.test(v.trim());
}

Try / catch

try {
  await cli.coupang.product({ productId });
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('numeric Coupang product ID')) {
    const extracted = normalizeProductId(productId) || normalizeProductId(url);
    if (extracted) return cli.coupang.product({ productId: extracted });
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing --product-id with: a Coupang URL instead of the bare ID (the URL branch only runs for label '--url'), a number shorter than 6 digits, an alphanumeric or whitespace-padded value like ' 1234567 ' is fine but 'abc123456' is not, or an empty/undefined value.

Common situations: Copying the whole product URL into the --product-id flag, truncating the ID when copying, using an internal SKU/vendor code that is not the Coupang product ID, or shell quoting issues that leave the flag empty.

Related errors


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