{"record":{"id":"1f11079efe56194b","repo":"jackwener/OpenCLI","slug":"1688-store-expects-a-store-url-or-member-id","errorCode":null,"errorMessage":"1688 store expects a store URL or member ID","messagePattern":"1688 store expects a store URL or member ID","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/1688/shared.js","lineNumber":145,"sourceCode":"}\nexport function buildSearchUrl(query) {\n    const normalized = cleanText(query);\n    if (!normalized) {\n        throw new ArgumentError('1688 search query cannot be empty', 'Example: opencli 1688 search \"桌面置物架\" --limit 20');\n    }\n    return `${SEARCH_URL_PREFIX}${encodeURIComponent(normalized)}`;\n}\nexport function buildDetailUrl(input) {\n    const offerId = extractOfferId(input);\n    if (!offerId) {\n        throw new ArgumentError('1688 item expects an offer URL or offer ID', 'Example: opencli 1688 item 887904326744');\n    }\n    return `${DETAIL_URL_PREFIX}${offerId}.html`;\n}\nexport function resolveStoreUrl(input) {\n    const normalized = cleanText(input);\n    if (!normalized) {\n        throw new ArgumentError('1688 store expects a store URL or member ID', 'Example: opencli 1688 store https://yinuoweierfushi.1688.com/');\n    }\n    const memberId = extractMemberId(normalized);\n    if (memberId) {\n        return `${STORE_MOBILE_URL_PREFIX}${memberId}`;\n    }\n    if (/^https?:\\/\\//i.test(normalized)) {\n        return canonicalizeStoreUrl(normalized);\n    }\n    if (normalized.endsWith('.1688.com')) {\n        return canonicalizeStoreUrl(`https://${normalized}`);\n    }\n    if (/^[a-z0-9-]+$/i.test(normalized)) {\n        return canonicalizeStoreUrl(`https://${normalized}.1688.com`);\n    }\n    throw new ArgumentError('1688 store expects a store URL or member ID', 'Example: opencli 1688 store b2b-22154705262941f196');\n}\nexport function canonicalizeStoreUrl(input) {\n    const url = parse1688Url(input);","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/1688/shared.js#L127-L163","documentation":"resolveStoreUrl normalizes a store URL or member ID into a canonical 1688 store URL. If the cleaned input is empty, it immediately throws ArgumentError with an example, because nothing was supplied at all. This is an upfront guard so the rest of the resolution logic (extractMemberId, URL parsing) only runs on non-empty input.","triggerScenarios":"Calling resolveStoreUrl (via resolvedUrl) with '', '   ', null, or undefined — e.g. a CLI flag not provided, an env/config variable unset, or an upstream field that failed to populate.","commonSituations":"Missing OPENCLI config/env value for the store URL; a script variable that an earlier step failed to set; copy-paste that dropped the whole value; calling the 1688 store command without its URL argument.","solutions":["Supply a store URL such as https://yinuoweierfushi.1688.com/ or a member ID to the store command.","Check that the environment variable or config entry feeding the argument is actually set (echo/print it before the call).","Add an emptiness check on the input before calling, to fail with a clearer app-level message."],"exampleFix":"// before\nconst url = resolveStoreUrl(process.env.STORE_URL); // STORE_URL unset -> empty string\n// after\nconst input = process.env.STORE_URL;\nif (!input?.trim()) throw new Error('STORE_URL is required, e.g. https://yourshop.1688.com/');\nconst url = resolveStoreUrl(input);","handlingStrategy":"validation","validationCode":"function requireStoreInput(input) {\n  if (typeof input !== 'string' || !input.trim()) {\n    throw new Error('1688 store input required: a store URL or member ID (e.g. https://shop.1688.com/)');\n  }\n  return input.trim();\n}\nresolveStoreUrl(requireStoreInput(process.env.STORE_URL));","typeGuard":"function hasStoreInput(input) {\n  return typeof input === 'string' && input.trim().length > 0;\n}","tryCatchPattern":"try {\n  const url = resolveStoreUrl(input);\n} catch (e) {\n  if (e.name === 'ArgumentError') {\n    console.error('Store URL/member ID missing or empty — check the --store flag or STORE_URL env var.');\n  } else throw e;\n}","preventionTips":["Echo the argument value (length + prefix) in logs before invoking store commands.","Set required values via explicit flags rather than relying on possibly-unset env vars.","Fail fast at CLI arg-parse time when the store argument is absent.","Keep a known-good example store URL in your integration tests."],"tags":["argument-validation","missing-input","empty-string"],"backgroundTag":"invalid-input-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}