jackwener/OpenCLI · error · ArgumentError

Invalid Amazon URL

Error message

Invalid Amazon URL

What it means

An ArgumentError raised by canonicalizeAmazonUrl when the input cannot be parsed as a URL at all, or parses but the hostname is not a recognized Amazon marketplace host. The library swallows the underlying reason (including an internal 'not-amazon' marker) and rethrows this single clear message.

Source

Thrown at clis/amazon/shared.js:265

    }
    catch {
        return null;
    }
    return null;
}
export function resolveBestsellersUrl(input) {
    return resolveRankingUrl('bestsellers', input);
}
export function canonicalizeAmazonUrl(input) {
    try {
        const url = new URL(input);
        if (!isAmazonMarketplaceHost(url.hostname)) {
            throw new Error('not-amazon');
        }
        return url.toString();
    }
    catch {
        throw new ArgumentError('Invalid Amazon URL');
    }
}
export function toAbsoluteAmazonUrl(value) {
    const normalized = cleanText(value);
    if (!normalized)
        return null;
    try {
        return new URL(normalized, HOME_URL).toString();
    }
    catch {
        return null;
    }
}
export function normalizeProductUrl(value) {
    const normalized = cleanText(value);
    const asin = extractAsin(normalized);
    if (asin)
        return buildProductUrl(normalized);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Fix the URL so it parses and points to an amazon.com (or supported marketplace) host
  2. Add the https:// scheme before the host
  3. Check the hostname spelling and that the marketplace is supported by this library

Example fix

// before
resolveRankingUrl('https://amazom.com/zgbs/electronics')
// after
resolveRankingUrl('https://www.amazon.com/zgbs/electronics')
Defensive patterns

Strategy: validation

Validate before calling

function isAmazonUrl(value) {
  try { const u = new URL(value); return /(^|\.)amazon\.[\w.]+$/.test(u.hostname); }
  catch { return false; }
}
if (!isAmazonUrl(input)) throw new Error(`'${input}' is not a valid Amazon URL`);

Type guard

const isParseableAmazonUrl = (v) => { try { return /(^|\.)amazon\.[\w.]+$/.test(new URL(v).hostname); } catch { return false; } };

Try / catch

try {
  const canonical = canonicalizeAmazonUrl(input);
} catch (err) {
  if (err.message === 'Invalid Amazon URL') {
    // fix scheme/hostname or reject the input upstream
  } else throw err;
}

Prevention

When it happens

Trigger: canonicalizeAmazonUrl('not a url'), a URL with a typo in the host (amazom.com), a URL missing the scheme where the parser fails entirely, or any non-Amazon hostname passed via the ranking URL resolution path.

Common situations: Typos in the domain; passing a search engine redirect or tracking URL whose final host isn't amazon.*; URLs from other marketplaces (amazon.cn variants not in the supported host list); fully-percent-encoded strings that break URL parsing.

Related errors


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