{"record":{"id":"02661d886927ea5a","repo":"juanfont/headscale","slug":"user-already-exists","errorCode":null,"errorMessage":"user already exists","messagePattern":"user already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/db/users.go","lineNumber":15,"sourceCode":"package db\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strconv\"\n\t\"testing\"\n\n\t\"github.com/juanfont/headscale/hscontrol/types\"\n\t\"github.com/juanfont/headscale/hscontrol/util\"\n\t\"gorm.io/gorm\"\n)\n\nvar (\n\tErrUserExists        = errors.New(\"user already exists\")\n\tErrUserNotFound      = errors.New(\"user not found\")\n\tErrUserStillHasNodes = errors.New(\"user not empty: node(s) found\")\n\tErrUserNotUnique     = errors.New(\"expected exactly one user\")\n)\n\nfunc (hsdb *HSDatabase) CreateUser(user types.User) (*types.User, error) {\n\treturn Write(hsdb.DB, func(tx *gorm.DB) (*types.User, error) {\n\t\treturn CreateUser(tx, user)\n\t})\n}\n\n// CreateUser creates a new [types.User]. Returns error if could not be created\n// or another user already exists.\nfunc CreateUser(tx *gorm.DB, user types.User) (*types.User, error) {\n\terr := util.ValidateUsername(user.Name)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/db/users.go#L1-L33","documentation":"Error \"user already exists\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/db/users.go:15 when the library encounters an invalid state.","commonSituations":"Raised when creating a user whose name already exists. Check existing users first (headscale users list) and pick a unique name, or reuse the existing user.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (user already exists); retry the operation after fixing the input, configuration, or environment."],"exampleFix":"Inspect the wrapped error for the underlying cause and correct the failing condition (user already exists); retry the operation after fixing the input, configuration, or environment.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}