{"record":{"id":"3387c187335d4bb2","repo":"ppy/osu","slug":"a-channel-with-the-name-channelname-could-not-be","errorCode":null,"errorMessage":"A channel with the name {channelName} could not be found.","messagePattern":"A channel with the name (.+?) could not be found\\.","errorType":"exception","errorClass":"ChannelNotFoundException","httpStatus":null,"severity":"error","filePath":"osu.Game/Online/Chat/ChannelManager.cs","lineNumber":157,"sourceCode":"            foreach (var joinedChannel in joinedChannels)\r\n                joinedChannel.Joined.Value = false;\r\n\r\n            joinedChannels.Clear();\r\n            // additionally clear the history of last joined channels so that the new user can't reopen the old user's channels\r\n            // (would likely fail web-side on perms anyway, but why even get that far)\r\n            closedChannels.Clear();\r\n        }\r\n\r\n        /// <summary>\r\n        /// Opens a channel or switches to the channel if already opened.\r\n        /// </summary>\r\n        /// <exception cref=\"ChannelNotFoundException\">If the name of the specifed channel was not found this exception will be thrown.</exception>\r\n        /// <param name=\"name\"></param>\r\n        public void OpenChannel(string name)\r\n        {\r\n            ArgumentNullException.ThrowIfNull(name);\r\n\r\n            CurrentChannel.Value = AvailableChannels.FirstOrDefault(c => c.Name == name) ?? throw new ChannelNotFoundException(name);\r\n        }\r\n\r\n        /// <summary>\r\n        /// Opens a new private channel.\r\n        /// </summary>\r\n        /// <param name=\"user\">The user the private channel is opened with.</param>\r\n        public void OpenPrivateChannel(APIUser user)\r\n        {\r\n            ArgumentNullException.ThrowIfNull(user);\r\n\r\n            if (user.Id == api.LocalUser.Value.Id)\r\n                return;\r\n\r\n            CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Type == ChannelType.PM && c.Users.Count == 1 && c.Users.Any(u => u.Id == user.Id))\r\n                                   ?? JoinChannel(new Channel(user));\r\n        }\r\n\r\n        private void currentChannelChanged(ValueChangedEvent<Channel> channel)\r","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Online/Chat/ChannelManager.cs#L139-L175","documentation":"Thrown by ChannelManager.OpenChannel when no channel in AvailableChannels matches the requested name. It performs a FirstOrDefault by Name and throws ChannelNotFoundException(name) on miss. Documented via <exception cref=\"ChannelNotFoundException\">. This is the join-path for already-known public channels, not the API join path.","triggerScenarios":"Calling OpenChannel(name) with a channel name that isn't currently in AvailableChannels — e.g. a channel that hasn't been fetched/joined, a typo, or a channel the server hasn't returned. Only pre-existing AvailableChannels are searched; it does not query the server.","commonSituations":"Deep links or commands opening a channel by name before the channel list has loaded; reopening a channel after it was closed/removed; typos in chat commands; trying to open a private/PM channel via OpenChannel (PMs go through OpenPrivateChannel).","solutions":["Check AvailableChannels.FirstOrDefault(c => c.Name == name) before calling OpenChannel, and fall back to JoinChannel or a server lookup if absent.","Ensure the channel list has been populated (API request completed) before invoking OpenChannel from external triggers.","For user-supplied names, validate existence and surface a user-friendly 'channel not found' message instead of propagating the exception."],"exampleFix":"// before\nchannelManager.OpenChannel(\"#somechannel\"); // throws if not in AvailableChannels\n\n// after\nvar channel = channelManager.AvailableChannels.FirstOrDefault(c => c.Name == name);\nif (channel != null)\n    channelManager.CurrentChannel.Value = channel;\nelse\n    Notifications.Post(new SimpleNotification { Text = $\"Channel '{name}' was not found.\" });","handlingStrategy":"validation","validationCode":"var channel = channelManager.AvailableChannels.FirstOrDefault(c => c.Name == name);\nif (channel == null) { /* notify 'channel not found' or request server join */ return; }\nchannelManager.CurrentChannel.Value = channel;","typeGuard":"static bool ChannelIsAvailable(ChannelManager cm, string name)\n    => cm.AvailableChannels.Any(c => c.Name == name);","tryCatchPattern":"try { channelManager.OpenChannel(name); }\ncatch (ChannelNotFoundException) { /* fall back to JoinChannel or show 'not found' */ }","preventionTips":["Populate/await the AvailableChannels list before auto-opening channels from deep links.","For PM channels, use OpenPrivateChannel(user), not OpenChannel(name).","Validate user-supplied channel names and surface friendly errors."],"tags":["chat","channels","api","validation","user-input"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}