jackwener/OpenCLI · error · ArgumentError
At least one Twitter/X username is required
Error message
At least one Twitter/X username is required
What it means
parseBatchUsernames throws ArgumentError when its input string is empty or only whitespace (String(input || '').trim() yields ''). The follow-batch command requires at least one Twitter/X screen name to act on. This is a usage/argument validation error (ARGUMENT, usage exit code).
Source
Thrown at clis/twitter/follow-batch.js:12
import { ArgumentError, AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { unwrapBrowserResult } from './shared.js';
const USERNAME_RE = /^[A-Za-z0-9_]{1,15}$/;
const DEFAULT_DELAY_MS = 3000;
const MAX_DELAY_MS = 60000;
export function parseBatchUsernames(input) {
const raw = String(input || '').trim();
if (!raw) {
throw new ArgumentError('At least one Twitter/X username is required');
}
const usernames = [];
const seen = new Set();
for (const part of raw.split(',')) {
const username = part.trim().replace(/^@+/, '');
if (!username) continue;
if (!USERNAME_RE.test(username)) {
throw new ArgumentError(`Invalid Twitter/X username: ${JSON.stringify(part.trim())}`);
}
const key = username.toLowerCase();
if (seen.has(key)) continue;
seen.add(key);
usernames.push(username);
}
if (!usernames.length) {
throw new ArgumentError('At least one Twitter/X username is required');View on GitHub (pinned to 49907e53dc)
Solutions
- Pass at least one username: `opencli twitter follow-batch '@alice'` or comma-separated '@alice,@bob'.
- If sourcing from a variable/file, check it is non-empty before invoking (e.g. [ -n "$USERS" ] || exit 1).
- Quote the variable ("$USERS") so the shell passes it correctly even when it contains commas/spaces.
Example fix
// before
await cli({ usernames: process.env.USERS }) // USERS unset -> ''
// after
if (!process.env.USERS) throw new Error('USERS env var required');
await cli({ usernames: process.env.USERS }) Defensive patterns
Strategy: validation
Validate before calling
function requireUsernames(input) {
const raw = String(input ?? '').trim();
if (!raw) throw new Error('usernames: at least one Twitter/X screen name is required');
return raw;
}
// in shell: [ -n "$USERS" ] || { echo 'USERS required' >&2; exit 1; } Type guard
function hasUsernames(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await followBatch(usernames);
} catch (e) {
if (e.code === 'ARGUMENT') {
console.error('Usage: twitter follow-batch <@user1,@user2> [--delay-ms N]');
process.exitCode = 2;
} else throw e;
} Prevention
- Always quote positional username arguments in shell scripts.
- Check env/config variables are non-empty before passing them as `usernames`.
- Remember `String(input || '')` coerces null/undefined/0 to empty — supply real values.
- Build follow lists programmatically and assert length >= 1 before invoking.
When it happens
Trigger: Running `twitter follow-batch` without the required positional `usernames` argument; passing an empty string (usernames: '') or whitespace-only string; passing null/undefined programmatically (|| '' collapses falsy values).
Common situations: Shell quoting mistakes that drop the positional arg (e.g. an unexpanded empty variable $USERS); scripting the CLI and forgetting the argument; calling the exported function directly with an optional/undefined value.
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
- delay-ms must be an integer between 0 and ${MAX_DELAY_MS}
- twitter mute-word keyword cannot be empty
- <train-no> must not be empty
- station must not be empty
- ${label} cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6e5230065e54ac37.
Report an issue: GitHub.