{"record":{"id":"f65da91b60f5590b","repo":"fullstackhero/dotnet-starter-kit","slug":"only-named-channels-can-be-renamed","errorCode":null,"errorMessage":"Only named Channels can be renamed.","messagePattern":"Only named Channels can be renamed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Modules/Chat/Modules.Chat/Domain/ChatChannel.cs","lineNumber":152,"sourceCode":"            CreatedAtUtc = DateTime.UtcNow,\n        };\n        foreach (var uid in userIds.Distinct(StringComparer.Ordinal))\n        {\n            var role = string.Equals(uid, creatorUserId, StringComparison.Ordinal)\n                ? ChannelMemberRole.Admin\n                : ChannelMemberRole.Member;\n            c._members.Add(ChannelMember.Create(c.Id, uid, role));\n        }\n        c.AddDomainEvent(DomainEvent.Create((id, ts) =>\n            new ChannelCreatedDomainEvent(c.Id, c.Type, null, creatorUserId, id, ts)));\n        return c;\n    }\n\n    public void Rename(string name, string? description)\n    {\n        if (Type != ChannelType.Channel)\n        {\n            throw new InvalidOperationException(\"Only named Channels can be renamed.\");\n        }\n        ArgumentException.ThrowIfNullOrWhiteSpace(name);\n        Name = name.Trim();\n        Slug = Slugify(name);\n        Description = description?.Trim();\n        UpdatedAtUtc = DateTime.UtcNow;\n    }\n\n    public void SetPrivate(bool isPrivate)\n    {\n        if (Type != ChannelType.Channel)\n        {\n            throw new InvalidOperationException(\"Only named Channels can change privacy.\");\n        }\n        IsPrivate = isPrivate;\n        UpdatedAtUtc = DateTime.UtcNow;\n    }\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/fullstackhero/dotnet-starter-kit/blob/3f2959e683e9f83f13e55e1678c9119f63c7e8e5/src/Modules/Chat/Modules.Chat/Domain/ChatChannel.cs#L134-L170","documentation":"ChatChannel.Rename only applies to channels whose Type is ChannelType.Channel (named channels). Calling it on a DM or group DM throws InvalidOperationException because DMs have no user-visible name/slug to change.","triggerScenarios":"channel.Rename(name, description) invoked on a channel created via CreateDirect or CreateGroupDm (Type == DirectMessage or GroupMessage).","commonSituations":"A generic 'edit channel' dialog wired to all channel types without filtering; bulk admin scripts renaming every channel in a workspace; UI state that loses the channel type after refresh and shows rename for DMs too.","solutions":["Guard before calling: only show/allow rename when channel.Type == ChannelType.Channel.","Disable the rename action in the UI for DMs and group DMs.","For group DMs, model a display label at the client level instead of renaming the entity.","In server code, check the channel type and return 400/409 rather than letting the domain throw."],"exampleFix":"// before\nchannel.Rename(newName, newDescription);\n// after\nif (channel.Type != ChannelType.Channel)\n    return Results.BadRequest(\"Only named channels can be renamed.\");\nchannel.Rename(newName, newDescription);","handlingStrategy":"validation","validationCode":"// before calling Rename\nif (channel.Type != ChannelType.Channel)\n    throw new ValidationException(\"Only named channels can be renamed\");\nif (string.IsNullOrWhiteSpace(newName))\n    throw new ValidationException(\"Name is required\");","typeGuard":"bool CanRename(ChatChannel c) => c.Type == ChannelType.Channel;","tryCatchPattern":"try { channel.Rename(name, description); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"renamed\")) { return Results.Conflict(ex.Message); }","preventionTips":["Gate the rename UI on channel.Type == ChannelType.Channel.","Never bulk-rename channels without filtering by type.","Represent DM/group labels client-side instead of renaming the entity.","Add an architecture/unit test asserting Rename throws for DM types."],"tags":["chat","invalid-state","rename","domain","channel-type"],"backgroundTag":"invalid-state-transition","analyzedSha":"3f2959e683e9f83f13e55e1678c9119f63c7e8e5","analyzedAt":"2026-09-15T22:20:53.684Z","contentChangedAt":"2026-09-15T22:20:53.684Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}