lyarenei / jellyfin-plugin-listenbrainz

ListenBrainz plugin for Jellyfin.
MIT License
78 stars 3 forks source link

Unhandled Exception for tracks with MusicBrainz IDs of deleted release #1

Closed rigrig closed 3 years ago

rigrig commented 3 years ago

Jellyfin started restarting after every song from a particular album, it looks like the Listenbrainz plugin crashes when trying to look up songs which are tagged with a MusicBrainz ID which no longer exists. It was playing song tagged with this (deleted) release group: https://musicbrainz.org/edit/70120662 I'm not sure if the individual tracks also pointed at deleted track IDs, or whether those still existed. Retagging my files with identifiers from a existing release fixed it.

Jellyfin Version: 10.7.5 Plugin version: 1.1.0.0 Operating System: Linux (docker on Synology NAS) Architecture: X64

What looks like the relevant part of my Docker log:

[16:58:20] [INF] Getting Recording ID for Track ID: f1ff0ccd-b2d9-4cb6-b0fe-858e8b44d790
[16:58:20] [INF] Playback Started
[16:58:20] [FTL] Unhandled Exception
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Jellyfin.Plugin.Listenbrainz.Models.Musicbrainz.Responses.RecordingIdResponse.GetData()
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Jellyfin.Plugin.Listenbrainz.Models.Musicbrainz.Responses.RecordingIdResponse.GetData()
   at Jellyfin.Plugin.Listenbrainz.Api.LbApiClient.GetRecordingId(String trackName, String trackMbId)
   at Jellyfin.Plugin.Listenbrainz.Api.LbApiClient.BuildListenRequest(Audio item, Boolean includeTimestamp)
   at Jellyfin.Plugin.Listenbrainz.Api.LbApiClient.NowPlaying(Audio item, LbUser user)
   at Jellyfin.Plugin.Listenbrainz.ServerEntryPoint.PlaybackStart(Object sender, PlaybackProgressEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)
   at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Reproducing it right now will be a bit involved, as all the tags are fixed and it no longer crashes. But if necessary I can try to manually set some invalid tags, or (probably) dig up a broken version from my backup. (I'm hoping it's just a matter of "Ah-hah, there is a missing check for unexpected empty results at line such-and-so")

lyarenei commented 3 years ago

Hi, sorry for not noticing the issue sooner. Also thank you for such a detailed bug report, that's something one does not usually see. :)

(I'm hoping it's just a matter of "Ah-hah, there is a missing check for unexpected empty results at line such-and-so")

Yes, you are absolutely right. The API just didn't return any results in that case and I naively didn't check for such state in the code. Anyway, as you can see I have fixed the error handling and it should work now. I also fixed sending listenings in such case, because the listens were rejected as they had an invalid MBID.

Feel free to reopen the issue if anything occurs in regards to this.

rigrig commented 3 years ago

Thanks for fixing it (and creating this plugin in the first place)! No need to apologize for how you spend your time, and fixing bugs within a week is actually quite fast.