jackwener/OpenCLI · error · ArgumentError
Invalid 1688 URL
Error message
Invalid 1688 URL
What it means
parse1688Url validates that an input is a URL under 1688.com; after cleaning tracking params and hash it throws ArgumentError('Invalid 1688 URL') when URL construction fails or the host is not a 1688.com domain. This is the low-level URL parser guard underpinning extractOfferId, extractMemberId, and canonicalization helpers.
Source
Thrown at clis/1688/shared.js:498
.replace(/\s*([~-])\s*/g, '$1')
.trim();
}
function escapeForRegex(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function parse1688Url(input) {
const normalized = cleanText(input);
try {
const url = new URL(normalized);
if (!url.hostname.endsWith('.1688.com') && url.hostname !== '1688.com' && url.hostname !== 'www.1688.com') {
throw new Error('invalid-host');
}
stripTrackingParams(url);
url.hash = '';
return url;
}
catch {
throw new ArgumentError('Invalid 1688 URL', 'Use a URL under 1688.com (for example: https://detail.1688.com/offer/887904326744.html)');
}
}
function parse1688UrlOrNull(input) {
try {
return parse1688Url(input);
}
catch {
return null;
}
}
function normalizeStoreHost(hostname) {
const lower = cleanText(hostname).toLowerCase();
if (!lower.endsWith('.1688.com'))
return null;
const [subdomain] = lower.split('.');
if (!subdomain || STORE_GENERIC_HOSTS.has(subdomain))
return null;
return lower;View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a full URL on the 1688.com domain, e.g. https://detail.1688.com/offer/887904326744.html.
- Prepend the scheme if missing: 'www.1688.com' -> 'https://www.1688.com'.
- If you have a bare offer ID, pass it to the item command directly rather than a URL-parsing path.
Example fix
// before
parse1688Url('detail.1688.com/offer/887904326744.html'); // no scheme
// after
parse1688Url('https://detail.1688.com/offer/887904326744.html'); Defensive patterns
Strategy: validation
Validate before calling
function is1688Url(input) {
try {
const u = new URL(String(input).trim());
return /(^|\.)1688\.com$/i.test(u.hostname);
} catch {
return false;
}
}
if (!is1688Url(input)) throw new Error(`Not a 1688.com URL: ${input}`); Type guard
function isValidAbsoluteUrl(input) {
try { new URL(String(input)); return true; } catch { return false; }
} Try / catch
try {
const parsed = parse1688Url(input);
} catch (e) {
if (e.name === 'ArgumentError') {
console.error(`Invalid URL '${input}' — must be an absolute https URL under 1688.com.`);
} else throw e;
} Prevention
- Always pass absolute URLs including the https:// scheme.
- Reject non-1688 domains (taobao, alibaba.com) at input boundaries.
- Trim surrounding whitespace/quotes from pasted URLs.
- Prefer ID-based commands (offer ID) when you don't have a full URL.
When it happens
Trigger: Passing a string that is not a valid absolute URL (new URL() throws) or a valid URL on a non-1688.com domain — e.g. 'item 887904326744' reached a parse path expecting a URL, 'https://taobao.com/x', 'www.1688.com' without scheme, or gibberish text.
Common situations: Copying a taobao/alibaba (non-1688) link; forgetting the https:// scheme; pasting text with surrounding quotes or markdown; calling parse helpers directly with IDs instead of URLs.
Related errors
- 1688 item expects an offer URL or offer ID
- Invalid 1688 store URL
- tid must be a numeric thread id
- kind
- direction
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9dd072515c8214d9.
Report an issue: GitHub.