Skip to content

fix: don't crash on a Spotify page error while unshuffling (#324)#333

Merged
devgianlu merged 1 commit into
masterfrom
fix/paged-list-404-crash
Jul 18, 2026
Merged

fix: don't crash on a Spotify page error while unshuffling (#324)#333
devgianlu merged 1 commit into
masterfrom
fix/paged-list-404-crash

Conversation

@devgianlu

Copy link
Copy Markdown
Owner

Problem

Reported in #324: the daemon crashes with

panic: invalid paged list position: -1
        tracks.(*pagedList[...]).iterHere(...)  tracks/paged-list.go:82

when a page fetch to Spotify fails (e.g. a 404 from radio-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 at pos == -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 (the TrySeek → moveStart fallback keeps pos >= 0), but the same class of bug is still reachable via List.ToggleShuffle:

  • The unshuffle-by-refetch branch calls tl.tracks.clear() (which sets pos = -1) and then a Seek that re-pages the context to find the current track.
  • If that Seek hits a page error, ToggleShuffle returns early with the list stranded at pos = -1.
  • The next player event (advanceNextGoNext/NextTracks/CurrentTrack) then panics.

clear() is the only thing that resets pos to -1 after load, and this was its only caller.

Fix

Snapshot (list, pos) before the destructive clear() and roll back on a failed re-fetch, so the list is never left at pos = -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

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>
@devgianlu
devgianlu merged commit 4afa96e into master Jul 18, 2026
8 checks passed
@devgianlu
devgianlu deleted the fix/paged-list-404-crash branch July 18, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash triggered by 404 from spotify

1 participant