{"record":{"id":"464d568afd3524c7","repo":"juanfont/headscale","slug":"updating-policy-after-user-deletion-w","errorCode":null,"errorMessage":"updating policy after user deletion: %w","messagePattern":"updating policy after user deletion: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"hscontrol/state/state.go","lineNumber":467,"sourceCode":"\treturn user, c, nil\n}\n\n// DeleteUser permanently removes a user and all associated data (nodes, API keys, etc).\n// This operation is irreversible.\n// It also updates the policy manager to ensure ACL policies referencing the deleted\n// user are re-evaluated immediately, fixing issue #2967.\nfunc (s *State) DeleteUser(userID types.UserID) (change.Change, error) {\n\terr := s.db.DestroyUser(userID)\n\tif err != nil {\n\t\treturn change.Change{}, err\n\t}\n\n\t// Update policy manager with the new user list (without the deleted user)\n\t// This ensures that if the policy references the deleted user, it gets\n\t// re-evaluated immediately rather than when some other operation triggers it.\n\tc, err := s.updatePolicyManagerUsers()\n\tif err != nil {\n\t\treturn change.Change{}, fmt.Errorf(\"updating policy after user deletion: %w\", err)\n\t}\n\n\t// If the policy manager doesn't detect changes, still return UserRemoved\n\t// to ensure peer lists are refreshed\n\tif c.IsEmpty() {\n\t\tc = change.UserRemoved()\n\t}\n\n\treturn c, nil\n}\n\n// RenameUser changes a user's name. The new name must be unique.\nfunc (s *State) RenameUser(userID types.UserID, newName string) (*types.User, change.Change, error) {\n\treturn s.UpdateUser(userID, func(user *types.User) error {\n\t\tuser.Name = newName\n\t\treturn nil\n\t})\n}","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/state/state.go#L449-L485","documentation":"Error \"updating policy after user deletion: %w\" thrown in juanfont/headscale.","triggerScenarios":"Thrown at hscontrol/state/state.go:467 when the library encounters an invalid state.","commonSituations":"Refreshing the policy after deleting a user failed. Remove references to the deleted user from the policy.","solutions":["Inspect the wrapped error for the underlying cause and correct the failing condition (updating policy after user deletion); retry the operation after fixing the input, configuration, or environment."],"exampleFix":"Inspect the wrapped error for the underlying cause and correct the failing condition (updating policy after user deletion); 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"}