{"record":{"id":"f7ac72e150c0840d","repo":"jackwener/OpenCLI","slug":"at-least-one-username-is-required","errorCode":null,"errorMessage":"At least one username is required","messagePattern":"At least one username is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/twitter/list-batch-utils.js","lineNumber":10,"sourceCode":"import { ArgumentError, AuthRequiredError } from '@jackwener/opencli/errors';\n\nconst USERNAME_RE = /^[A-Za-z0-9_]{1,15}$/;\nconst DEFAULT_INTERVAL_SECONDS = 5;\nconst MAX_INTERVAL_SECONDS = 600;\n\nexport function parseCommaSeparatedUsernames(rawValue, example) {\n    const raw = String(rawValue || '').trim();\n    if (!raw) {\n        throw new ArgumentError('At least one username is required', example);\n    }\n\n    const values = raw\n        .split(',')\n        .map((part) => part.trim().replace(/^@/, ''))\n        .filter(Boolean);\n\n    if (values.length === 0) {\n        throw new ArgumentError('At least one username is required', example);\n    }\n\n    const seen = new Set();\n    const usernames = [];\n    for (const username of values) {\n        if (!USERNAME_RE.test(username)) {\n            throw new ArgumentError(`Invalid Twitter/X username: ${JSON.stringify(username)}`, example);\n        }\n        const key = username.toLowerCase();","sourceCodeStart":1,"sourceCodeEnd":28,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/list-batch-utils.js#L1-L28","documentation":"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.","triggerScenarios":"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 ''.","commonSituations":"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.","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\"."],"exampleFix":"// before\nopencli twitter list-batch-add 123456789 --usernames \"$USERS\"   # USERS unset\nArgumentError: At least one username is required\n// after\nUSERS=\"alice,bob\"\nopencli twitter list-batch-add 123456789 --usernames \"$USERS\"","handlingStrategy":"validation","validationCode":"if (!process.env.USERS || !process.env.USERS.trim()) {\n  throw new Error('USERS is empty; supply --usernames \"alice,bob\"');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runBatch(argv);\n} catch (e) {\n  if (e instanceof ArgumentError && /At least one username is required/.test(e.message)) {\n    console.error('Usage: opencli twitter list-batch-add <listId> --usernames \"alice,bob\"');\n    process.exitCode = 2;\n    return;\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["argument-validation","cli","input"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}