{"record":{"id":"2e6dc45073cca733","repo":"juanfont/headscale","slug":"creating-user-w-2e6dc4","errorCode":null,"errorMessage":"creating user: %w","messagePattern":"creating user: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"hscontrol/state/state.go","lineNumber":392,"sourceCode":"\t// meaning that we do not need to send individual route changes.\n\tcs = append(cs, rcs...)\n\n\tif len(rcs) > 0 || policyChanged {\n\t\tlog.Info().\n\t\t\tBool(\"policy.changed\", policyChanged).\n\t\t\tInt(\"route.changes\", len(rcs)).\n\t\t\tInt(\"total.changes\", len(cs)).\n\t\t\tMsg(\"Policy reload completed with changes\")\n\t}\n\n\treturn cs, nil\n}\n\n// CreateUser creates a new user and updates the policy manager.\n// Returns the created user, change set, and any error.\nfunc (s *State) CreateUser(user types.User) (*types.User, change.Change, error) {\n\tif err := s.db.DB.Save(&user).Error; err != nil { //nolint:noinlineerr\n\t\treturn nil, change.Change{}, fmt.Errorf(\"creating user: %w\", err)\n\t}\n\n\t// Check if policy manager needs updating\n\tc, err := s.updatePolicyManagerUsers()\n\tif err != nil {\n\t\t// Log the error but don't fail the user creation\n\t\treturn &user, change.Change{}, fmt.Errorf(\"updating policy manager after user creation: %w\", err)\n\t}\n\n\t// Even if the policy manager doesn't detect a filter change, SSH policies\n\t// might now be resolvable when they weren't before. If there are existing\n\t// nodes, we should send a policy change to ensure they get updated SSH policies.\n\t// TODO(kradalby): detect this, or rebuild all SSH policies so we can determine\n\t// this upstream.\n\tif c.IsEmpty() {\n\t\tc = change.PolicyChange()\n\t}\n","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/state/state.go#L374-L410","documentation":"Error \"creating user: %w\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/state/state.go:392 when the library encounters an invalid state.","commonSituations":"Creating the user in state/database failed. The name may already exist or violate username rules.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (creating user); retry the operation after fixing the input, configuration, or environment."],"exampleFix":"Inspect the wrapped error for the underlying cause and correct the failing condition (creating user); 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"}