jackwener/OpenCLI · error · ArgumentError
twitter following user cannot be empty
Error message
twitter following user cannot be empty
What it means
ArgumentError thrown by the `twitter following` command when no target user could be determined. The command requires either an explicit @screen_name argument or a resolvable logged-in user from the session; both were empty, so it refuses to run and shows a usage example.
Source
Thrown at clis/twitter/following.js:178
await page.goto('https://x.com/home');
await page.wait({ selector: '[data-testid="primaryColumn"]' });
// Bridge wraps primitive page.evaluate returns as { session, data:<value> };
// unwrap so the href string is usable downstream.
// NOTE: the function-literal form `() => ...` silently drops
// primitive return values through the bridge — only the template
// string form preserves the `data` field.
const href = unwrapBrowserResult(await page.evaluate(`() => {
const link = document.querySelector('a[data-testid="AppTabBar_Profile_Link"]');
return link ? link.getAttribute('href') : null;
}`));
if (!href || typeof href !== 'string')
throw new AuthRequiredError('x.com', 'Could not detect logged-in user. Are you logged in?');
targetUser = normalizeScreenName(href);
if (!targetUser)
throw new AuthRequiredError('x.com', 'Could not detect logged-in user. Are you logged in?');
}
if (!targetUser) {
throw new ArgumentError('twitter following user cannot be empty', 'Example: opencli twitter following @elonmusk --limit 200');
}
const followingQueryId = await resolveTwitterQueryId(page, 'Following', FOLLOWING_QUERY_ID);
const userByScreenNameQueryId = await resolveTwitterQueryId(page, 'UserByScreenName', USER_BY_SCREEN_NAME_QUERY_ID);
const headers = {
'Authorization': `Bearer ${decodeURIComponent(TWITTER_BEARER_TOKEN)}`,
'X-Csrf-Token': ct0,
'X-Twitter-Auth-Type': 'OAuth2Session',
'X-Twitter-Active-User': 'yes',
};
// Get userId from screen_name
const userLookup = unwrapBrowserResult(await page.evaluate(async (url, headers) => {
const resp = await fetch(url, { headers, credentials: 'include' });
if (!resp.ok) return { error: resp.status };
const d = await resp.json();
return { userId: d.data?.user?.result?.rest_id || null };
}, buildUserByScreenNameQueryUrl(userByScreenNameQueryId, targetUser), headers));View on GitHub (pinned to 49907e53dc)
Solutions
- Pass the target screen name explicitly: `opencli twitter following @elonmusk --limit 200`
- If you intended your own account, log into x.com in the CLI browser session so targetUser resolves
- Check for typos in the argument (empty string, whitespace-only, or an unsupported format)
- Run `opencli twitter following --help` to confirm the expected argument form
Example fix
// before $ opencli twitter following // after $ opencli twitter following @elonmusk --limit 200
Defensive patterns
Strategy: validation
Validate before calling
function validateFollowingArgs(args) {
const user = (args[0] || '').trim();
if (!user || !/^@?[A-Za-z0-9_]{1,15}$/.test(user)) {
throw new Error('Usage: opencli twitter following @screenname --limit 200');
}
return user.startsWith('@') ? user : '@' + user;
} Type guard
function isValidScreenName(v) {
return typeof v === 'string' && /^@?[A-Za-z0-9_]{1,15}$/.test(v.trim());
} Try / catch
try {
await cli.following(normalizeScreenName(input));
} catch (err) {
if (err.name === 'ArgumentError') {
console.error('Missing/invalid user. Example: opencli twitter following @elonmusk --limit 200');
} else throw err;
} Prevention
- Always pass the positional @screen_name explicitly
- Validate the handle matches Twitter's 1-15 char [A-Za-z0-9_] rule before invoking
- If relying on the logged-in user default, confirm the session is authenticated first
- Check `--help` output when scripting to keep argument forms correct
When it happens
Trigger: Invoking `opencli twitter following` with no positional user argument and no logged-in x.com session (or a session whose screen name could not be normalized), leaving targetUser falsy after all fallbacks.
Common situations: Forgetting the positional argument entirely; passing an argument that normalizeScreenName rejects (e.g. a full profile URL not handled, or 'me' without being logged in); combining empty arg with an unauthenticated browser.
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 download requires either <username> or --tweet-url
- twitter followers user cannot be empty
- 12306 tk auth cookie missing
- ${probe.detail}
- 12306 whoami failed: ${probe.detail}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d36f467cef72bb16.
Report an issue: GitHub.