{"record":{"id":"16c3b6372193b1db","repo":"juanfont/headscale","slug":"user-not-empty-node-s-found","errorCode":null,"errorMessage":"user not empty: node(s) found","messagePattern":"user not empty: node\\(s\\) found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/db/users.go","lineNumber":17,"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}\n\n\terr = tx.Create(&user).Error","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/db/users.go#L1-L35","documentation":"Error \"user not empty: node(s) found\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/db/users.go:17 when the library encounters an invalid state.","commonSituations":"A user cannot be destroyed while nodes are still registered to it. Delete or move the user's nodes first, then destroy the user.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (user not empty); 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 not empty); 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-15T22:17:37.221Z"}