jackwener/OpenCLI · error · ArgumentError
At least one username is required
Error message
At least one username is required
What it means
parseCommaSeparatedUsernames (used by batch commands like list-batch-add via the `usernames` option) throws ArgumentError when the raw username string is empty after trimming — i.e. no value was supplied at all. The batch operation cannot run without at least one target username, and the optional `example` parameter is attached to the error as usage help.
Source
Thrown at clis/twitter/list-batch-utils.js:10
import { ArgumentError, AuthRequiredError } from '@jackwener/opencli/errors';
const USERNAME_RE = /^[A-Za-z0-9_]{1,15}$/;
const DEFAULT_INTERVAL_SECONDS = 5;
const MAX_INTERVAL_SECONDS = 600;
export function parseCommaSeparatedUsernames(rawValue, example) {
const raw = String(rawValue || '').trim();
if (!raw) {
throw new ArgumentError('At least one username is required', example);
}
const values = raw
.split(',')
.map((part) => part.trim().replace(/^@/, ''))
.filter(Boolean);
if (values.length === 0) {
throw new ArgumentError('At least one username is required', example);
}
const seen = new Set();
const usernames = [];
for (const username of values) {
if (!USERNAME_RE.test(username)) {
throw new ArgumentError(`Invalid Twitter/X username: ${JSON.stringify(username)}`, example);
}
const key = username.toLowerCase();View on GitHub (pinned to 49907e53dc)
Solutions
- Pass at least one username: --usernames alice (leading @ is allowed and stripped).
- If using a shell variable, check it is non-empty before invoking: [ -n "$USERS" ] || exit 1.
- Use comma-separation for multiple: --usernames "alice,bob,charlie".
Example fix
// before opencli twitter list-batch-add 123456789 --usernames "$USERS" # USERS unset ArgumentError: At least one username is required // after USERS="alice,bob" opencli twitter list-batch-add 123456789 --usernames "$USERS"
Defensive patterns
Strategy: validation
Validate before calling
if (!process.env.USERS || !process.env.USERS.trim()) {
throw new Error('USERS is empty; supply --usernames "alice,bob"');
} Try / catch
try {
await runBatch(argv);
} catch (e) {
if (e instanceof ArgumentError && /At least one username is required/.test(e.message)) {
console.error('Usage: opencli twitter list-batch-add <listId> --usernames "alice,bob"');
process.exitCode = 2;
return;
}
throw e;
} Prevention
- Check shell variables for emptiness before interpolating into --usernames.
- Add a preflight in scripts that fails fast when the username list is missing.
- Quote the flag value to avoid shell word-splitting dropping it.
When it happens
Trigger: Calling a batch command with the usernames option omitted, set to an empty string, or whitespace-only (e.g. --usernames "" or --usernames " "), so String(rawValue||'').trim() yields ''.
Common situations: Forgetting the --usernames flag in a script; a shell variable holding the list is empty/unset ($USERS expands to nothing); a config file passes an empty field; whitespace-only input from a spreadsheet copy.
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
- facebook marketplace-inbox --limit must be a positive intege
- Argument "content" is required.
- Jike search query cannot be empty
- --limit must be a positive integer
- --limit must be an integer between 1 and ${MAX_LIMIT}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f7ac72e150c0840d.
Report an issue: GitHub.