{"record":{"id":"8361a1bbad336b3c","repo":"TechnitiumSoftware/DnsServer","slug":"group-already-exists-newgroupname","errorCode":null,"errorMessage":"Group already exists: {newGroupName}","messagePattern":"Group already exists: (.+?)","errorType":"exception","errorClass":"DnsWebServiceException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Auth/AuthManager.cs","lineNumber":1092,"sourceCode":"\n            throw new DnsWebServiceException(\"Group already exists: \" + name);\n        }\n\n        public void RenameGroup(Group group, string newGroupName)\n        {\n            if (group.Name.Equals(newGroupName, StringComparison.OrdinalIgnoreCase))\n            {\n                group.Name = newGroupName;\n                return;\n            }\n\n            string oldGroupName = group.Name;\n            group.Name = newGroupName;\n\n            if (!_groups.TryAdd(group.Name.ToLowerInvariant(), group))\n            {\n                group.Name = oldGroupName; //revert\n                throw new DnsWebServiceException(\"Group already exists: \" + newGroupName);\n            }\n\n            _groups.TryRemove(oldGroupName.ToLowerInvariant(), out _);\n\n            //update users\n            foreach (KeyValuePair<string, User> user in _users)\n                user.Value.RenameGroup(oldGroupName);\n        }\n\n        public bool DeleteGroup(string name)\n        {\n            name = name.ToLowerInvariant();\n\n            switch (name)\n            {\n                case \"everyone\":\n                case \"administrators\":\n                case \"dns administrators\":","sourceCodeStart":1074,"sourceCodeEnd":1110,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Auth/AuthManager.cs#L1074-L1110","documentation":"Thrown as DnsWebServiceException from RenameGroup when TryAdd of the new lowercased name fails because it is already taken. The group's Name is reverted to the old value before throwing, and the old key is retained. Returned over the API as HTTP 200 with status 'error'.","triggerScenarios":"POST /api/groups/rename (or equivalent) targeting a newGroupName that already exists; the fast-path no-op only triggers when names are equal OrdinalIgnoreCase.","commonSituations":"Renaming to collide with an existing group; case-only rename attempt; trying to rename onto a built-in group's name.","solutions":["Pick a target name that does not exist (check case-insensitively).","Delete the conflicting group first if it is not built-in.","Verify the target name with GetGroup before renaming."],"exampleFix":"// before\n_authManager.RenameGroup(group, newGroupName);\n// after\nif (!_groups.ContainsKey(newGroupName.ToLowerInvariant()))\n    _authManager.RenameGroup(group, newGroupName);","handlingStrategy":"validation","validationCode":"if (await GetGroupAsync(newGroupName) is not null)\n    throw new InvalidOperationException($\"Group '{newGroupName}' is taken.\");","typeGuard":null,"tryCatchPattern":"try { await client.RenameGroupAsync(group, newGroupName); }\ncatch (HttpApiClientException ex) when (ex.Message.StartsWith(\"Group already exists\"))\n{\n    PromptForDifferentGroupName();\n}","preventionTips":["Verify the target name case-insensitively before renaming.","Do not attempt to rename onto a built-in group."],"tags":["auth","group-management","duplicate"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}