{"record":{"id":"21f118cdcf1662b3","repo":"jackwener/OpenCLI","slug":"invalid-amazon-url","errorCode":null,"errorMessage":"Invalid Amazon URL","messagePattern":"Invalid Amazon URL","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/amazon/shared.js","lineNumber":265,"sourceCode":"    }\n    catch {\n        return null;\n    }\n    return null;\n}\nexport function resolveBestsellersUrl(input) {\n    return resolveRankingUrl('bestsellers', input);\n}\nexport function canonicalizeAmazonUrl(input) {\n    try {\n        const url = new URL(input);\n        if (!isAmazonMarketplaceHost(url.hostname)) {\n            throw new Error('not-amazon');\n        }\n        return url.toString();\n    }\n    catch {\n        throw new ArgumentError('Invalid Amazon URL');\n    }\n}\nexport function toAbsoluteAmazonUrl(value) {\n    const normalized = cleanText(value);\n    if (!normalized)\n        return null;\n    try {\n        return new URL(normalized, HOME_URL).toString();\n    }\n    catch {\n        return null;\n    }\n}\nexport function normalizeProductUrl(value) {\n    const normalized = cleanText(value);\n    const asin = extractAsin(normalized);\n    if (asin)\n        return buildProductUrl(normalized);","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/amazon/shared.js#L247-L283","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the URL so it parses and points to an amazon.com (or supported marketplace) host","Add the https:// scheme before the host","Check the hostname spelling and that the marketplace is supported by this library"],"exampleFix":"// before\nresolveRankingUrl('https://amazom.com/zgbs/electronics')\n// after\nresolveRankingUrl('https://www.amazon.com/zgbs/electronics')","handlingStrategy":"validation","validationCode":"function isAmazonUrl(value) {\n  try { const u = new URL(value); return /(^|\\.)amazon\\.[\\w.]+$/.test(u.hostname); }\n  catch { return false; }\n}\nif (!isAmazonUrl(input)) throw new Error(`'${input}' is not a valid Amazon URL`);","typeGuard":"const isParseableAmazonUrl = (v) => { try { return /(^|\\.)amazon\\.[\\w.]+$/.test(new URL(v).hostname); } catch { return false; } };","tryCatchPattern":"try {\n  const canonical = canonicalizeAmazonUrl(input);\n} catch (err) {\n  if (err.message === 'Invalid Amazon URL') {\n    // fix scheme/hostname or reject the input upstream\n  } else throw err;\n}","preventionTips":["Always include the https:// scheme","Check hostname spelling (amazon.com, not amazom.com)","Only pass URLs on supported Amazon marketplaces","Resolve tracking/redirect URLs to their final amazon destination first"],"tags":["validation","url-parsing","amazon-host"],"backgroundTag":"invalid-url-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}