don't crash on All Tracks page if API call to get album tracks fails

This commit is contained in:
Drew Weymouth
2025-07-12 09:10:13 -07:00
parent 6f7b54b779
commit 9c56429ed4
@@ -41,15 +41,19 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
// fetch next album // fetch next album
if a.curAlbum == nil || a.curTrackIdx >= len(a.curAlbum.Tracks) { if a.curAlbum == nil || a.curTrackIdx >= len(a.curAlbum.Tracks) {
haveNextAlbum := false
for !haveNextAlbum && !a.done {
al := a.albumIter.Next() al := a.albumIter.Next()
if al == nil { if al == nil {
a.done = true a.done = true
return nil return nil
} }
alWithTracks, err := a.s.GetAlbum(al.ID) alWithTracks, err := a.s.GetAlbum(al.ID)
if err != nil { if err != nil || alWithTracks == nil {
log.Printf("error fetching album: %s", err.Error()) log.Printf("error fetching album: %s", err.Error())
continue // try next album
} }
haveNextAlbum = true
if len(alWithTracks.Tracks) == 0 { if len(alWithTracks.Tracks) == 0 {
// in the unlikely case of an album with zero tracks, // in the unlikely case of an album with zero tracks,
// just call recursively to move to next album // just call recursively to move to next album
@@ -58,6 +62,7 @@ func (a *allTracksIterator) Next() *mediaprovider.Track {
a.curAlbum = alWithTracks a.curAlbum = alWithTracks
a.curTrackIdx = 0 a.curTrackIdx = 0
} }
}
tr := a.curAlbum.Tracks[a.curTrackIdx] tr := a.curAlbum.Tracks[a.curTrackIdx]
a.curTrackIdx += 1 a.curTrackIdx += 1