jackwener/OpenCLI · error · ArgumentError
Invalid mode: ${JSON.stringify(kwargs.mode)}. Expected "publ
Error message
Invalid mode: ${JSON.stringify(kwargs.mode)}. Expected "public" or "private". What it means
This ArgumentError is thrown by parseListCreateArgs when the --mode value is not exactly "public" or "private" (case-insensitive, whitespace-trimmed). The value is normalized via String(...).trim().toLowerCase() before the check, so only genuinely different words fail. The message shows the raw input JSON-stringified.
Source
Thrown at clis/twitter/list-create.js:35
responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
responsive_web_graphql_timeline_navigation_enabled: true,
};
export function parseListCreateArgs(kwargs) {
const name = String(kwargs.name || '').trim();
const description = String(kwargs.description || '').trim();
const modeRaw = String(kwargs.mode || 'public').trim().toLowerCase();
if (!name) {
throw new ArgumentError('List name is required', 'Example: opencli twitter list-create "My List"');
}
if (name.length > NAME_MAX) {
throw new ArgumentError(`List name too long: ${name.length} chars (max ${NAME_MAX})`);
}
if (description.length > DESCRIPTION_MAX) {
throw new ArgumentError(`Description too long: ${description.length} chars (max ${DESCRIPTION_MAX})`);
}
if (modeRaw !== 'public' && modeRaw !== 'private') {
throw new ArgumentError(`Invalid mode: ${JSON.stringify(kwargs.mode)}. Expected "public" or "private".`);
}
return { listName: name, listDescription: description, listMode: modeRaw, privateFlag: modeRaw === 'private' };
}
function requireCreateListResult(result, expectedName, expectedMode) {
if (!result || typeof result !== 'object') {
throw new CommandExecutionError(`Unexpected result from twitter list-create: ${JSON.stringify(result)}`);
}
if (result.httpStatus === 401 || result.httpStatus === 403) {
throw new AuthRequiredError('x.com', `Twitter CreateList returned HTTP ${result.httpStatus}`);
}
if (!result.ok) {
const snippet = String(result.bodyText || '').slice(0, 300);
throw new CommandExecutionError(`HTTP ${result.httpStatus} from CreateList: ${snippet}`);
}
if (!result.bodyJson || typeof result.bodyJson !== 'object') {
throw new CommandExecutionError(`CreateList returned malformed JSON payload. Body: ${String(result.bodyText || '').slice(0, 300)}`);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Use --mode public or --mode private exactly (case/spacing is normalized automatically)
- Omit --mode to get the default "public"
- Check the source of the value (config/env/script) for typos or empty strings
Example fix
// before opencli twitter list-create "My List" --mode protected // after opencli twitter list-create "My List" --mode private
Defensive patterns
Strategy: validation
Validate before calling
const VALID_MODES = ['public', 'private'];
const mode = String(modeArg || 'public').trim().toLowerCase();
if (!VALID_MODES.includes(mode)) {
throw new Error(`mode must be "public" or "private" (got ${JSON.stringify(modeArg)})`);
} Type guard
function isValidListMode(mode) {
return typeof mode === 'string' && ['public', 'private'].includes(mode.trim().toLowerCase());
} Try / catch
try {
await opencli.twitter.listCreate({ name, description, mode });
} catch (e) {
if (e instanceof ArgumentError && /Invalid mode/.test(e.message)) {
console.error('Use --mode public or --mode private.');
} else { throw e; }
} Prevention
- Whitelist mode values at config/env-var read time
- Normalize (trim + lowercase) before validating, matching the CLI's behavior
- Prefer omitting --mode when the default (public) is intended
When it happens
Trigger: Calling `opencli twitter list-create "Name" --mode protected` or `--mode ""` or `--mode "Public "` variants that don't match; passing mode with a typo like "privte".
Common situations: Confusing Twitter list modes with other platforms' visibility terms (protected/unlisted/secret); reading the mode from a config file or env var that holds an unexpected value; empty string from an unset variable.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid jobType: ${input}
- --category must be one of ${RECOMMEND_CATEGORIES.join(', ')}
- --resume-file requires --all
- twitter download requires either <username> or --tweet-url
- Use either <username> or --tweet-url, not both
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/6c9c69e94b4a4b13.
Report an issue: GitHub.