jackwener/OpenCLI · error · ArgumentError
invalid video URL: ${raw}
Error message
invalid video URL: ${raw} What it means
parseTikTokVideoUrl runs new URL(raw) to parse the input; if the string is not a valid absolute URL, the constructor throws and this ArgumentError is raised with the raw input echoed back.
Source
Thrown at clis/tiktok/utils.js:116
// Parses a TikTok video URL into {username, videoId, url}. Rejects bad
// shapes up-front so we never `goto()` an arbitrary page and silently
// pretend the click target was found. Both share-style links
// (vm.tiktok.com/...) and bare video IDs are out of scope — callers must
// pass the canonical /@user/video/id form.
export function parseTikTokVideoUrl(value) {
const raw = String(value ?? '').trim();
if (!raw) {
throw new ArgumentError(
'video URL is required',
'Example: opencli tiktok comment https://www.tiktok.com/@user/video/1234567890 "..."',
);
}
let parsed;
try {
parsed = new URL(raw);
} catch {
throw new ArgumentError(
`invalid video URL: ${raw}`,
'Example: https://www.tiktok.com/@user/video/1234567890',
);
}
if (!/(^|\.)tiktok\.com$/i.test(parsed.hostname)) {
throw new ArgumentError(
`URL must be on tiktok.com (got ${parsed.hostname})`,
'Example: https://www.tiktok.com/@user/video/1234567890',
);
}
const match = parsed.pathname.match(/^\/@([A-Za-z0-9._-]+)\/video\/(\d+)\/?$/);
if (!match) {
throw new ArgumentError(
'URL must follow /@<username>/video/<id> format',
'Example: https://www.tiktok.com/@user/video/1234567890',
);
}
return {View on GitHub (pinned to 49907e53dc)
Solutions
- Prefix the value with the scheme: https:// before the hostname
- Pass the full canonical form https://www.tiktok.com/@user/video/<id>
- If you only have a video ID, construct the URL yourself: `https://www.tiktok.com/@user/video/${id}`
Example fix
// before
parseTikTokVideoUrl('www.tiktok.com/@user/video/123')
// after
parseTikTokVideoUrl('https://www.tiktok.com/@user/video/123') Defensive patterns
Strategy: validation
Validate before calling
new URL(value); // will throw SyntaxError early if not an absolute URL
Type guard
const isAbsoluteUrl = (v) => { try { return Boolean(new URL(String(v))); } catch { return false; } }; Try / catch
try { parseTikTokVideoUrl(raw); } catch (e) { if (/^invalid video URL:/.test(e.message)) console.error('Include the https:// scheme'); else throw e; } Prevention
- Always include https:// when storing TikTok URLs
- Normalize IDs to full URLs at ingestion time
- Lint configs for URL-typed fields with new URL()
When it happens
Trigger: Passing a bare video ID, a share link without scheme (www.tiktok.com/...), or any string that fails the URL constructor.
Common situations: Passing '1234567890' instead of a URL; copy-pasting a URL that lost its https:// scheme; vm.tiktok.com share links are also fine as URLs but fail later at the path check — this one fires before host checking.
Related errors
- '${rawInput}' does not look like an autohome series id (a nu
- bilibili follow target must be a valid space.bilibili.com/<u
- chatgpt project commands require a chatgpt.com project id or
- Invalid Chess.com game URL: "${value}" Expected https://www.
- event query parameter must be a numeric event id
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/70cb159fa23c4e7b.
Report an issue: GitHub.