jackwener/OpenCLI · error · ArgumentError

amazon discussion expects an ASIN or product URL

Error message

amazon discussion expects an ASIN or product URL

What it means

An ArgumentError thrown by buildDiscussionUrl when no ASIN can be extracted from the input, so a product-reviews URL cannot be built. Same family as the product variant, but for the `amazon discussion` command; it fails fast with a usage example.

Source

Thrown at clis/amazon/shared.js:153

        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);
        return getRankingSpec(listType).pathPattern.test(url.pathname);
    }
    catch {
        return false;
    }
}
export function resolveRankingUrl(listType, input) {
    const spec = getRankingSpec(listType);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide a valid 10-character ASIN, e.g. B0FJS72893
  2. Provide the full Amazon product URL containing /dp/<ASIN>
  3. Check that the variable feeding the argument holds an ASIN, not a title or review link

Example fix

// before
opencli amazon discussion 'my favorite blender'
// after
opencli amazon discussion B0FJS72893
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Try / catch

try {
  const url = buildDiscussionUrl(input);
} catch (err) {
  if (err.message.includes('discussion expects an ASIN')) {
    // correct the input to a valid ASIN
  } else throw err;
}

Prevention

When it happens

Trigger: Calling `opencli amazon discussion` with a blank value, a plain title, a non-Amazon URL, or a URL whose /dp/<ASIN> segment is missing or malformed.

Common situations: Scripting the discussion command with a value scraped from the wrong column; pasting a review permalink instead of the product URL; typos in the ASIN.

Related errors


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