{"record":{"id":"1c7538d1cb8dc90b","repo":"ppy/osu","slug":"the-room-s-current-item-cannot-be-removed","errorCode":null,"errorMessage":"The room's current item cannot be removed.","messagePattern":"The room's current item cannot be removed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs","lineNumber":596,"sourceCode":"            ServerAPIRoom.Playlist = ServerAPIRoom.Playlist.Select((pi, i) => pi.ID == item.ID ? new PlaylistItem(item) : ServerAPIRoom.Playlist[i]).ToArray();\r\n\r\n            await ((IMultiplayerClient)this).PlaylistItemChanged(clone(item)).ConfigureAwait(false);\r\n        }\r\n\r\n        public override Task EditPlaylistItem(MultiplayerPlaylistItem item) => EditUserPlaylistItem(api.LocalUser.Value.OnlineID, clone(item));\r\n\r\n        public async Task RemoveUserPlaylistItem(int userId, long playlistItemId)\r\n        {\r\n            Debug.Assert(ServerRoom != null);\r\n            Debug.Assert(ServerAPIRoom != null);\r\n\r\n            var item = ServerRoom.Playlist.FirstOrDefault(i => i.ID == playlistItemId);\r\n\r\n            if (item == null)\r\n                throw new InvalidOperationException(\"Item does not exist in the room.\");\r\n\r\n            if (item.Equals(currentItem))\r\n                throw new InvalidOperationException(\"The room's current item cannot be removed.\");\r\n\r\n            if (item.OwnerID != userId)\r\n                throw new InvalidOperationException(\"Attempted to remove an item which is not owned by the user.\");\r\n\r\n            if (item.Expired)\r\n                throw new InvalidOperationException(\"Attempted to remove an item which has already been played.\");\r\n\r\n            ServerRoom.Playlist.Remove(item);\r\n            ServerAPIRoom.Playlist = ServerAPIRoom.Playlist.Where(i => i.ID != item.ID).ToArray();\r\n            await ((IMultiplayerClient)this).PlaylistItemRemoved(clone(playlistItemId)).ConfigureAwait(false);\r\n\r\n            await updateCurrentItem(ServerRoom).ConfigureAwait(false);\r\n            updateRoomStateIfRequired();\r\n        }\r\n\r\n        public override Task RemovePlaylistItem(long playlistItemId) => RemoveUserPlaylistItem(api.LocalUser.Value.OnlineID, clone(playlistItemId));\r\n\r\n        public override Task VoteToSkipIntro()\r","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Tests/Visual/Multiplayer/TestMultiplayerClient.cs#L578-L614","documentation":"RemoveUserPlaylistItem protects the currently-active playlist item (currentItem, i.e. ServerRoom.Playlist[currentIndex]) from removal to keep room state consistent while a beatmap is in play. Removing it throws.","triggerScenarios":"Calling RemovePlaylistItem with the ID of the item currently being played (item.Equals(currentItem) is true).","commonSituations":"Test tries to remove the item that the room is actively on; currentItem pointer was not advanced before removal.","solutions":["Remove a different (non-current) playlist item.","Advance the room past the item (finish/advance the match so currentItem changes) before removing it.","If clearing the playlist, expire/skip the current item first via the normal flow."],"exampleFix":"// before\nawait client.RemovePlaylistItem(currentItem.ID.Value); // throws\n\n// after\n// remove a queued (non-current) item instead:\nawait client.RemovePlaylistItem(ServerRoom.Playlist.First(i => i.ID != currentItem.ID && !i.Expired).ID);","handlingStrategy":"validation","validationCode":"if (playlistItemId == currentItem?.ID)\n    throw new InvalidOperationException(\"cannot remove the active item\");\nawait client.RemovePlaylistItem(playlistItemId);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never remove the currentItem; advance the match first if you must.","Pick removal candidates where i.ID != currentItem.ID.","Centralize removal behind a helper that skips the current item."],"tags":["test-infra","multiplayer","playlist","lifecycle"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}