{"record":{"id":"474015d7b5d864ee","repo":"jackwener/OpenCLI","slug":"amazon-discussion-expects-an-asin-or-product-url","errorCode":null,"errorMessage":"amazon discussion expects an ASIN or product URL","messagePattern":"amazon discussion expects an ASIN or product URL","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/amazon/shared.js","lineNumber":153,"sourceCode":"        const url = new URL(normalized);\n        return isAmazonMarketplaceHost(url.hostname) ? url.hostname : null;\n    }\n    catch {\n        return null;\n    }\n}\nexport function buildProductUrl(input) {\n    const asin = extractAsin(input);\n    if (!asin) {\n        throw new ArgumentError('amazon product expects an ASIN or product URL', 'Example: opencli amazon product B0FJS72893');\n    }\n    const host = amazonHostFromInput(input);\n    return host ? `https://${host}/dp/${asin}` : `${PRODUCT_URL_PREFIX}${asin}`;\n}\nexport function buildDiscussionUrl(input) {\n    const asin = extractAsin(input);\n    if (!asin) {\n        throw new ArgumentError('amazon discussion expects an ASIN or product URL', 'Example: opencli amazon discussion B0FJS72893');\n    }\n    const host = amazonHostFromInput(input);\n    return host ? `https://${host}/product-reviews/${asin}` : `${DISCUSSION_URL_PREFIX}${asin}`;\n}\nfunction getRankingSpec(listType) {\n    return AMAZON_RANKING_SPECS[listType];\n}\nexport function isSupportedRankingPath(listType, inputUrl) {\n    try {\n        const url = new URL(inputUrl);\n        return getRankingSpec(listType).pathPattern.test(url.pathname);\n    }\n    catch {\n        return false;\n    }\n}\nexport function resolveRankingUrl(listType, input) {\n    const spec = getRankingSpec(listType);","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/amazon/shared.js#L135-L171","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide a valid 10-character ASIN, e.g. B0FJS72893","Provide the full Amazon product URL containing /dp/<ASIN>","Check that the variable feeding the argument holds an ASIN, not a title or review link"],"exampleFix":"// before\nopencli amazon discussion 'my favorite blender'\n// after\nopencli amazon discussion B0FJS72893","handlingStrategy":"validation","validationCode":"const ASIN_RE = /^[0-9A-Z]{10}$/;\nif (!ASIN_RE.test(input ?? '')) throw new Error(`'${input}' is not a valid ASIN for discussion lookup`);","typeGuard":"const isAsin = (v) => typeof v === 'string' && /^[0-9A-Z]{10}$/.test(v.trim());","tryCatchPattern":"try {\n  const url = buildDiscussionUrl(input);\n} catch (err) {\n  if (err.message.includes('discussion expects an ASIN')) {\n    // correct the input to a valid ASIN\n  } else throw err;\n}","preventionTips":["Use the product's ASIN, not its title or a review permalink","Validate with a 10-char alphanumeric check first","Extract the ASIN from the product URL with /dp/([0-9A-Z]{10})/ before calling"],"tags":["validation","asin","bad-input"],"backgroundTag":"invalid-asin-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}