{"record":{"id":"2e843779d28d80a1","repo":"jackwener/OpenCLI","slug":"amazon-search-query-cannot-be-empty","errorCode":null,"errorMessage":"amazon search query cannot be empty","messagePattern":"amazon search query cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/amazon/shared.js","lineNumber":116,"sourceCode":"            .map((line) => line.replace(/\\s+/g, ' ').trim())\n            .filter(Boolean)\n            .join('\\n')\n        : '';\n}\nexport function uniqueNonEmpty(values) {\n    return [...new Set(values.map((value) => cleanText(value)).filter(Boolean))];\n}\nexport function buildProvenance(sourceUrl) {\n    return {\n        source_url: sourceUrl,\n        fetched_at: new Date().toISOString(),\n        strategy: STRATEGY,\n    };\n}\nexport function buildSearchUrl(query) {\n    const normalized = cleanText(query);\n    if (!normalized) {\n        throw new ArgumentError('amazon search query cannot be empty');\n    }\n    return `${SEARCH_URL_PREFIX}${encodeURIComponent(normalized)}`;\n}\nexport function extractAsin(input) {\n    const normalized = cleanText(input);\n    if (!normalized)\n        return null;\n    if (/^[A-Z0-9]{10}$/i.test(normalized)) {\n        return normalized.toUpperCase();\n    }\n    const match = normalized.match(/\\/(?:dp|gp\\/product|product-reviews)\\/([A-Z0-9]{10})/i);\n    return match ? match[1].toUpperCase() : null;\n}\nexport function amazonHostFromInput(input) {\n    const normalized = cleanText(input);\n    if (!normalized)\n        return null;\n    try {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/amazon/shared.js#L98-L134","documentation":"An ArgumentError thrown by buildSearchUrl when the search query is empty or whitespace after cleaning. The library refuses to construct a search URL without a query because it would produce an invalid Amazon search endpoint. This is a fail-fast input validation error, not a scraping failure.","triggerScenarios":"Calling buildSearchUrl('') or buildSearchUrl('   ') directly, or passing an empty --query/positional argument to the amazon search command (e.g. from an unquoted shell variable that expands to nothing).","commonSituations":"Shell script with an unset variable: `opencli amazon search \"$Q\"` where Q is empty; reading the query from a config file or env var that is missing; trimming reduced the input to nothing.","solutions":["Pass a non-empty query string to the search command","Check the shell variable/env var/config value feeding the query is set and non-blank","Trim and validate the query in your script before invoking"],"exampleFix":"// before\nconst url = buildSearchUrl(query);\n// after\nif (!query?.trim()) throw new Error('query is required');\nconst url = buildSearchUrl(query);","handlingStrategy":"validation","validationCode":"const q = (process.env.SEARCH_QUERY ?? '').trim();\nif (!q) throw new Error('SEARCH_QUERY is empty — set it before calling amazon search');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  const url = buildSearchUrl(query);\n} catch (err) {\n  if (err.message.includes('query cannot be empty')) {\n    // fall back to a default query or surface a config error\n  } else throw err;\n}","preventionTips":["Quote shell variables: \"$Q\" and check they are set","Validate required inputs at script startup","Trim inputs before passing","Fail early on empty env/config values"],"tags":["validation","empty-argument"],"backgroundTag":"empty-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}