fix: don't crash on a Spotify page error while unshuffling (#324)#333
Merged
Conversation
ToggleShuffle's unshuffle branch clears the paged list (setting pos to -1) and then re-fetches the context in order to seek back to the current track. If that re-fetch hit a transient page error from Spotify (e.g. a 404 from radio-router while paging a station/autoplay context), the list was left stranded at pos -1. The next access via iterHere()/get() then panicked with "invalid paged list position: -1", crashing the daemon since the player event loop has no panic recovery. Snapshot the list before the destructive clear() and roll back to the previous valid state on failure, so the shuffle toggle simply does not take effect instead of corrupting the list. Fixes #324 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reported in #324: the daemon crashes with
when a page fetch to Spotify fails (e.g. a
404fromradio-router/v3/tracks/...while paging a station/autoplay context).Root cause
iterHere()/get()are invariant guards that assume a current position has been established (pos >= 0). A transient page-fetch failure can leave the track list stranded atpos == -1, and the next access panics. The player event loop has no panic recovery, so this takes down the whole daemon.On current
master, the specific autoplay path from the report is already mitigated (theTrySeek → moveStartfallback keepspos >= 0), but the same class of bug is still reachable viaList.ToggleShuffle:tl.tracks.clear()(which setspos = -1) and then aSeekthat re-pages the context to find the current track.Seekhits a page error,ToggleShufflereturns early with the list stranded atpos = -1.advanceNext→GoNext/NextTracks/CurrentTrack) then panics.clear()is the only thing that resetsposto-1after load, and this was its only caller.Fix
Snapshot
(list, pos)before the destructiveclear()and roll back on a failed re-fetch, so the list is never left atpos = -1. The rollback is atomic and total — on a transient error the list is restored to its exact prior (valid) state, and the shuffle toggle simply does not take effect.Testing
go build ./...go vet ./tracks/go test -tags test_unit ./tracks/(existing unit tests pass)Fixes #324
🤖 Generated with Claude Code