jackwener/OpenCLI · error · ArgumentError

spec.invalidInputMessage

Error message

spec.invalidInputMessage

What it means

An ArgumentError thrown by resolveRankingUrl when the normalized input is neither a canonical Amazon URL nor a bare amazon.* host+path, i.e. the string cannot be resolved into a ranking URL for the given list type (spec). The spec-specific invalidInputMessage/hint describe the expected format for that ranking command.

Source

Thrown at clis/amazon/shared.js:186

    }
}
export function resolveRankingUrl(listType, input) {
    const spec = getRankingSpec(listType);
    const normalized = cleanText(input);
    if (!normalized || normalized === 'root')
        return spec.rootUrl;
    let candidateUrl;
    if (normalized.startsWith('/')) {
        candidateUrl = new URL(normalized, HOME_URL).toString();
    }
    else if (/^https?:\/\//i.test(normalized)) {
        candidateUrl = canonicalizeAmazonUrl(normalized);
    }
    else if (normalized.includes('amazon.') && normalized.includes('/')) {
        candidateUrl = canonicalizeAmazonUrl(`https://${normalized.replace(/^\/+/, '')}`);
    }
    else {
        throw new ArgumentError(spec.invalidInputMessage, spec.invalidInputHint);
    }
    if (!isSupportedRankingPath(listType, candidateUrl)) {
        throw new ArgumentError(spec.invalidInputMessage, spec.invalidInputHint);
    }
    return normalizeRankingInputUrl(candidateUrl);
}
function normalizeRankingInputUrl(inputUrl) {
    try {
        const url = new URL(inputUrl);
        const normalizedPathSegments = url.pathname
            .split('/')
            .filter(Boolean)
            .filter((segment) => !/^ref=/i.test(segment));
        url.pathname = `/${normalizedPathSegments.join('/')}`;
        url.hash = '';
        // Ranking pages are frequently shared with tracking refs that can land on unstable variants.
        // Dropping ref keeps the canonical ranking path while preserving useful params (for example pg=2).
        url.searchParams.delete('ref');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a full https Amazon URL for the ranking page
  2. Use the documented shorthand (bare ASIN/category URL) per the command's --url help
  3. Check the input isn't a category name — look up the category URL instead

Example fix

// before
opencli amazon bestsellers --url 'electronics'
// after
opencli amazon bestsellers --url 'https://www.amazon.com/Best-Sellers-Electronics/zgbs/electronics'
Defensive patterns

Strategy: validation

Validate before calling

const looksLikeUrl = (s) => typeof s === 'string' && /^(https?:\/\/)?[\w.-]*amazon\.[\w.]+\/\S+/.test(s.trim());
if (!looksLikeUrl(rankingInput)) throw new Error(`'${rankingInput}' is not an Amazon URL`);

Try / catch

try {
  const url = resolveRankingUrl(input, spec);
} catch (err) {
  if (err.message === spec.invalidInputMessage) {
    // show spec.invalidInputHint to the user
  } else throw err;
}

Prevention

When it happens

Trigger: Calling resolveRankingUrl with a non-URL string (e.g. a category name), a URL without 'amazon.' in it, or a bare host with no path where a full URL is required by the branch logic.

Common situations: User passes 'electronics' instead of a URL; passes 'amazon.com/bestsellers' without scheme but with trailing characters the branch doesn't match; wrapping tool passes an encoded or mangled URL.

Related errors


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