jackwener/OpenCLI · error · ArgumentError
1688 item expects an offer URL or offer ID
Error message
1688 item expects an offer URL or offer ID
What it means
buildDetailUrl constructs a 1688 offer detail URL from an arbitrary input string. It first runs extractOfferId to pull an offer ID out of a URL or bare ID; when the input yields no offer ID it throws ArgumentError, so callers never build a malformed detail URL. The message tells the user what kind of value is expected, and the example fix shows the canonical CLI invocation.
Source
Thrown at clis/1688/shared.js:138
}
export function parseSearchLimit(input) {
const parsed = Number.parseInt(String(input ?? SEARCH_LIMIT_DEFAULT), 10);
if (!Number.isFinite(parsed) || parsed < 1) {
throw new ArgumentError('1688 search --limit must be a positive integer', 'Example: opencli 1688 search "桌面置物架" --limit 20');
}
return Math.min(SEARCH_LIMIT_MAX, parsed);
}
export function buildSearchUrl(query) {
const normalized = cleanText(query);
if (!normalized) {
throw new ArgumentError('1688 search query cannot be empty', 'Example: opencli 1688 search "桌面置物架" --limit 20');
}
return `${SEARCH_URL_PREFIX}${encodeURIComponent(normalized)}`;
}
export function buildDetailUrl(input) {
const offerId = extractOfferId(input);
if (!offerId) {
throw new ArgumentError('1688 item expects an offer URL or offer ID', 'Example: opencli 1688 item 887904326744');
}
return `${DETAIL_URL_PREFIX}${offerId}.html`;
}
export function resolveStoreUrl(input) {
const normalized = cleanText(input);
if (!normalized) {
throw new ArgumentError('1688 store expects a store URL or member ID', 'Example: opencli 1688 store https://yinuoweierfushi.1688.com/');
}
const memberId = extractMemberId(normalized);
if (memberId) {
return `${STORE_MOBILE_URL_PREFIX}${memberId}`;
}
if (/^https?:\/\//i.test(normalized)) {
return canonicalizeStoreUrl(normalized);
}
if (normalized.endsWith('.1688.com')) {
return canonicalizeStoreUrl(`https://${normalized}`);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a valid offer detail URL like https://detail.1688.com/offer/887904326744.html or the bare numeric offer ID (e.g. 887904326744).
- Strip whitespace/extra text and re-copy the offer ID from the browser address bar of the product page.
- Verify the input is a detail.1688.com offer URL, not a search/store page; if you only have a store URL use the store command instead of item.
Example fix
// before opencli 1688 item "https://www.1688.com" // no offer ID -> ArgumentError // after opencli 1688 item 887904326744 // or opencli 1688 item https://detail.1688.com/offer/887904326744.html
Defensive patterns
Strategy: validation
Validate before calling
const OFFER_ID_RE = /(\d{8,})/;
function hasOfferId(input) {
if (typeof input !== 'string' || !input.trim()) return false;
return /detail\.1688\.com\/offer\/\d+\.html/.test(input) || OFFER_ID_RE.test(input);
}
if (!hasOfferId(userInput)) throw new Error(`Not a 1688 offer URL/ID: ${userInput}`); Type guard
function isOfferUrl(input) {
return typeof input === 'string' && /^https:\/\/detail\.1688\.com\/offer\/\d+\.html$/.test(input.trim());
}
function isBareOfferId(input) {
return typeof input === 'string' && /^\d{8,}$/.test(input.trim());
} Try / catch
try {
const url = buildDetailUrl(input);
} catch (e) {
if (e.name === 'ArgumentError') {
console.error(`Bad 1688 item input: ${input}. Provide an offer URL or numeric offer ID.`);
} else throw e;
} Prevention
- Normalize input with trim() before passing.
- Prefer pasting the full detail.1688.com/offer/<id>.html URL over hand-typed IDs.
- Unit-test buildDetailUrl with search URLs and store URLs to confirm they are rejected early.
- Never pass null/undefined from upstream steps — assert input exists first.
When it happens
Trigger: Calling buildDetailUrl (via itemUrl/detailUrl) with an empty string, a 1688 search URL, a non-1688 URL, a URL without an offer/numeric ID segment, or a typo'd numeric ID containing letters/punctuation that extractOfferId cannot parse.
Common situations: Users paste a search results page or homepage instead of a product (offer) page; IDs copied from rendered pages include whitespace or punctuation; downstream systems pass null/undefined because an earlier scrape step failed; mixing up store URLs (subdomain.1688.com) with offer URLs.
Related errors
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/463439f909b72508.
Report an issue: GitHub.