jackwener/OpenCLI · error · ArgumentError

amazon product expects an ASIN or product URL

Error message

amazon product expects an ASIN or product URL

What it means

An ArgumentError thrown by buildProductUrl when the input contains neither a valid 10-character ASIN nor a recognizable Amazon product URL (extractAsin returned null). The library cannot construct a /dp/ product link without an ASIN, so it fails fast with usage guidance.

Source

Thrown at clis/amazon/shared.js:145

    const match = normalized.match(/\/(?:dp|gp\/product|product-reviews)\/([A-Z0-9]{10})/i);
    return match ? match[1].toUpperCase() : null;
}
export function amazonHostFromInput(input) {
    const normalized = cleanText(input);
    if (!normalized)
        return null;
    try {
        const url = new URL(normalized);
        return isAmazonMarketplaceHost(url.hostname) ? url.hostname : null;
    }
    catch {
        return null;
    }
}
export function buildProductUrl(input) {
    const asin = extractAsin(input);
    if (!asin) {
        throw new ArgumentError('amazon product expects an ASIN or product URL', 'Example: opencli amazon product B0FJS72893');
    }
    const host = amazonHostFromInput(input);
    return host ? `https://${host}/dp/${asin}` : `${PRODUCT_URL_PREFIX}${asin}`;
}
export function buildDiscussionUrl(input) {
    const asin = extractAsin(input);
    if (!asin) {
        throw new ArgumentError('amazon discussion expects an ASIN or product URL', 'Example: opencli amazon discussion B0FJS72893');
    }
    const host = amazonHostFromInput(input);
    return host ? `https://${host}/product-reviews/${asin}` : `${DISCUSSION_URL_PREFIX}${asin}`;
}
function getRankingSpec(listType) {
    return AMAZON_RANKING_SPECS[listType];
}
export function isSupportedRankingPath(listType, inputUrl) {
    try {
        const url = new URL(inputUrl);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a valid 10-character ASIN, e.g. B0FJS72893
  2. Paste the full Amazon product URL containing /dp/<ASIN>
  3. Verify you copied the ASIN from the product page and not a review or offer ID

Example fix

// before
opencli amazon product 'https://amzn.to/3xYz'
// after
opencli amazon product B0FJS72893
Defensive patterns

Strategy: validation

Validate before calling

const ASIN_RE = /^B?[0-9A-Z]{9,10}$/;
if (!ASIN_RE.test(input ?? '')) throw new Error(`'${input}' is not a valid ASIN`);

Type guard

const isAsin = (v) => typeof v === 'string' && /^[0-9A-Z]{10}$/.test(v.trim());

Try / catch

try {
  const url = buildProductUrl(input);
} catch (err) {
  if (err.message.includes('expects an ASIN or product URL')) {
    // prompt user for a valid ASIN or full /dp/ URL
  } else throw err;
}

Prevention

When it happens

Trigger: Passing a random string, a truncated URL missing the /dp/<ASIN> segment, an ASIN with wrong length/characters, or an empty input to `amazon product`, or to any call chain through productUrl/normalizeProductUrl.

Common situations: User pastes a shortened amzn.to link; a non-Amazon URL (eBay, another store); an 11-character or lowercase-invalid ID; copying only part of the product URL.

Related errors


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