jesseward / jellyfin-plugin-lastfm

LastFM plugin for the Jellyfin media system. Fork of the Emby Last.FM plug-in
178 stars 11 forks source link

Plugin crashes Jellyfin when trying to sync favourited track that has no metadata #57

Closed physicalmemory closed 7 months ago

physicalmemory commented 7 months ago

Hi there,

Thanks for your work in developing this plugin. I've encountered a bug that looks to be because I favourited a track that has no metadata in Jellyfin, which the plugin then tries to sync as a loved track to last.fm. The resulting error:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Jellyfin.Plugin.Lastfm.Api.LastfmApiClient.LoveTrack(Audio item, LastfmUser user, Boolean love)
   at Jellyfin.Plugin.Lastfm.ServerEntryPoint.UserDataSaved(Object sender, UserDataSaveEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_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()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

Then crashes my Jellyfin instance entirely. There is functionality included to skip scrobbling a track when no artist or track metadata is detected, could that potentially also be applied to loved tracks? That may work to resolve this issue.

jesseward commented 7 months ago

nice one, thanks for reporting @physicalmemory. I was able to repro this as well. I will work on a fix for this.

[15:54:06] [FTL] [34] Main: Unhandled Exception
System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Jellyfin.Plugin.Lastfm.Api.LastfmApiClient.LoveTrack(Audio item, LastfmUser user, Boolean love) in /workspaces/jellyfin-plugin-lastfm/Jellyfin.Plugin.Lastfm/Api/LastfmApiClient.cs:line 142
   at Jellyfin.Plugin.Lastfm.ServerEntryPoint.UserDataSaved(Object sender, UserDataSaveEventArgs e) in /workspaces/jellyfin-plugin-lastfm/Jellyfin.Plugin.Lastfm/ServerEntryPoint.cs:line 98
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_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()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
Unhandled exception. System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Jellyfin.Plugin.Lastfm.Api.LastfmApiClient.LoveTrack(Audio item, LastfmUser user, Boolean love) in /workspaces/jellyfin-plugin-lastfm/Jellyfin.Plugin.Lastfm/Api/LastfmApiClient.cs:line 142
   at Jellyfin.Plugin.Lastfm.ServerEntryPoint.UserDataSaved(Object sender, UserDataSaveEventArgs e) in /workspaces/jellyfin-plugin-lastfm/Jellyfin.Plugin.Lastfm/ServerEntryPoint.cs:line 98
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_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()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
jesseward commented 7 months ago

hey @physicalmemory, this has been addressed in v8.0.0.4 of the plugin. It's been pushed to the Plugin Repo as well (https://jellyfin-repo.jesseward.com/manifest.json).

Fix addressed in PR -> https://github.com/jesseward/jellyfin-plugin-lastfm/pull/58

You can uninstall and then reinstall the plugin to pick up the new version. Thanks again for reporting

physicalmemory commented 7 months ago

Just updated the plugin and that looks to have fixed it! No more crashes. Thanks for taking a look at this so quickly.