jackwener/OpenCLI · error · ArgumentError
twitter tweet URL cannot be empty
Error message
twitter tweet URL cannot be empty
What it means
ArgumentError from parseTweetUrl when the URL argument is empty or whitespace-only. parseTweetUrl is the shared validator used by retweet, like, quote and other tweet-targeting commands, so all of them fail fast with this error before any browser interaction.
Source
Thrown at clis/twitter/shared.js:50
'messages',
'notifications',
'privacy',
'search',
'settings',
'signup',
'tos',
]);
function isTwitterHost(hostname) {
return TWEET_HOSTS.has(hostname)
|| hostname.endsWith('.x.com')
|| hostname.endsWith('.twitter.com');
}
export function parseTweetUrl(rawUrl) {
const value = String(rawUrl ?? '').trim();
if (!value) {
throw new ArgumentError('twitter tweet URL cannot be empty', 'Example: opencli twitter retweet https://x.com/jack/status/20');
}
let parsed;
try {
parsed = new URL(value);
}
catch {
throw new ArgumentError(`Invalid tweet URL: ${value}`, 'Use a full https://x.com/<user>/status/<id> URL');
}
const hostname = parsed.hostname.toLowerCase();
if (parsed.protocol !== 'https:' || !isTwitterHost(hostname)) {
throw new ArgumentError(`Invalid tweet URL host: ${value}`, 'Use a full https://x.com/<user>/status/<id> URL');
}
const match = parsed.pathname.match(TWEET_PATH_PATTERN);
if (!match?.[1]) {
throw new ArgumentError(`Could not extract tweet ID from URL: ${value}`, 'Use a full https://x.com/<user>/status/<id> URL');
}
return {
id: match[1],View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a full tweet URL as the argument, e.g. https://x.com/jack/status/20
- Fix the shell/CI variable so it is non-empty before invoking
- Quote the URL to prevent the shell from eating it
Example fix
// before opencli twitter retweet "$TWEET_URL" # TWEET_URL empty // after TWEET_URL=https://x.com/jack/status/20 opencli twitter retweet "$TWEET_URL"
Defensive patterns
Strategy: validation
Validate before calling
function requireTweetUrl(v) {
const s = String(v ?? '').trim();
if (!s) throw new Error('tweet URL is required, e.g. https://x.com/jack/status/20');
return s;
} Type guard
function hasTweetUrl(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await opencli.twitter.retweet(url);
} catch (e) {
if (e.name === 'ArgumentError' && /cannot be empty/.test(e.message)) {
console.error('Provide a full tweet URL');
} else throw e;
} Prevention
- Validate env/config variables are non-empty before invoking
- Quote URLs in shell commands
- Require the positional argument in wrapper scripts
- Fail fast in CI if TWEET_URL is unset
When it happens
Trigger: `opencli twitter retweet ''`, passing an unset shell variable ($TWEET_URL expands to nothing), or calling the JS API with null/undefined/'' as rawUrl.
Common situations: CI variables not set, copy-paste losing the URL, scripts interpolating an empty field from JSON/YAML input, or forgetting the positional argument entirely.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- twitter search query is empty
- ${label} cannot be empty
- twitter profile username must be a valid Twitter/X handle
- Invalid --from username: ${JSON.stringify(kwargs.from)}
- twitter search --limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7f7f3bb822871d9f.
Report an issue: GitHub.