{"record":{"id":"6942a1367a47bde5","repo":"Mintplex-Labs/anything-llm","slug":"username-must-be-at-least-2-characters","errorCode":null,"errorMessage":"Username must be at least 2 characters","messagePattern":"Username must be at least 2 characters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/user.js","lineNumber":41,"sourceCode":"    \"role\",\n    \"suspended\",\n    \"dailyMessageLimit\",\n    \"bio\",\n  ],\n  validations: {\n    /**\n     * Unix-style username regex:\n     * - Must start with a lowercase letter\n     * - Can contain lowercase letters, digits, underscores, hyphens, @ signs, and periods\n     * - 2-64 characters long\n     */\n    username: (newValue = \"\") => {\n      try {\n        const username = String(newValue);\n        if (username.length > 64)\n          throw new Error(\"Username cannot be longer than 64 characters\");\n        if (username.length < 2)\n          throw new Error(\"Username must be at least 2 characters\");\n        if (!User.usernameRegex.test(username))\n          throw new Error(\n            \"Username must start with a lowercase letter and only contain lowercase letters, numbers, underscores, hyphens, and periods\"\n          );\n        return username;\n      } catch (e) {\n        throw new Error(e.message);\n      }\n    },\n    role: (role = \"default\") => {\n      const VALID_ROLES = [\"default\", \"admin\", \"manager\"];\n      if (!VALID_ROLES.includes(role)) {\n        throw new Error(\n          `Invalid role. Allowed roles are: ${VALID_ROLES.join(\", \")}`\n        );\n      }\n      return String(role);\n    },","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/user.js#L23-L59","documentation":"Thrown by User.validations.username when the stringified input is shorter than 2 characters. The username regex and length bounds together require 2-64 characters. Runs on user create and on username update paths.","triggerScenarios":"Creating or updating a user with a single-character username, or an empty/whitespace string (once coerced).","commonSituations":"Form allows a 1-character handle. Automated import maps an empty field to a placeholder single character. Typo in a migration script.","solutions":["Provide a username of at least 2 characters.","If generating handles programmatically, pad or choose a longer base name.","Validate length on the client before submit."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (typeof username !== 'string' || username.trim().length < 2) {\n  throw new Error('Username must be at least 2 characters');\n}","typeGuard":"const isMinLengthOk = (u) => typeof u === 'string' && u.length >= 2;","tryCatchPattern":null,"preventionTips":["Require a minimum length of 2 in the UI.","Reject empty/whitespace handles before submission."],"tags":["validation","user","length-limit"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}