fix: resolve crashes and white screen when playing/loading songs - #65
fix: resolve crashes and white screen when playing/loading songs#65ujjawalkaushik1110 wants to merge 4 commits into
Conversation
## Critical Bugs Fixed: - converter.ht: fullAlbums() returned undefined instead of [] - track.ht: null pointer crash in radio() when no playlist found - browse.ht: syntax error - missing comma after spTCookie parameter - user.ht: savedPlaylists() used wrong variable in callback - auth.ht: randomBytesFromMath() had no return statement - auth.ht: duplicate 'mode' parameter in getToken() - auth.ht: null pointer when credentials null in refreshCredentials() - album.ht: missing export statement ## Enhancements: - Added comprehensive null safety across all converter functions - Added null checks for all endpoint functions - Functions now return empty arrays/objects instead of crashing - Fixed track extraction from playlist/saved items - Fixed album extraction from saved albums - Added optional chaining for nested property access - Added default values for missing fields - Improved main plugin initialization with proper auth callback Fixes sonic-liberation#64 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR targets the crashes/white-screen behavior when playing or loading Spotify content by adding null-safety/fallback handling across endpoints and converters, plus tightening auth/token initialization.
Changes:
- Added null/empty-input guards across multiple endpoint methods (track/album/artist/playlist/user/search/browse) with safer fallbacks instead of throwing.
- Fixed converter and endpoint data-shape issues (e.g., saved tracks/albums/playlists wrappers;
fullAlbums()returning[]instead ofundefined). - Improved auth/token wiring so the API access token is refreshed into
SpotifyGqlApion auth state changes.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/converter/converter.ht | Adds null-safe pagination and safer conversions/default values; fixes fullAlbums() empty-case return. |
| src/segments/auth.ht | Fixes missing return in randomBytesFromMath, removes duplicate mode param, and guards refreshCredentials() when credentials are null. |
| src/segments/browse.ht | Fixes syntax error and adds empty-result fallback for sections(); exports BrowseEndpoint. |
| src/segments/track.ht | Adds null checks for getTrack/radio, introduces getTracks, and guards save/unsave inputs. |
| src/segments/user.ht | Adds fallbacks for me() and paginated saved items; fixes playlist converter callback input; adds guards for library-check methods. |
| src/segments/playlist.ht | Adds guards/fallbacks, unwraps playlist track items to actual tracks, and makes mutating operations return success booleans. |
| src/segments/artist.ht | Adds guards/fallbacks and introduces getArtists, plus safer handling for top-tracks/related responses. |
| src/segments/album.ht | Adds guards/fallbacks, introduces getAlbums, and makes save/unsave return success booleans; exports AlbumEndpoint. |
| src/segments/search.ht | Adds empty-query/data-null fallbacks for all search endpoints. |
| src/plugin.ht | Updates plugin initialization to react to auth events and safely set the API access token. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return client.browse.homeSection( | ||
| id, | ||
| id, | ||
| timeZone: timeZone, | ||
| spTCookie: auth.credentials["cookies"].where((c)=>c["name"] == "sp_t").elementAt(0)["value"], | ||
| offset: offset, |
There was a problem hiding this comment.
Same issue as sections(): spTCookie access uses .elementAt(0) on a filtered cookies list and will throw when credentials/cookies are missing or sp_t isn't present. Add null/empty checks and a safe cookie lookup before calling client.browse.homeSection(...), otherwise this endpoint can still crash when unauthenticated.
| return client.browse.home( | ||
| timeZone: timeZone, | ||
| spTCookie: auth.credentials["cookies"].where((c)=>c["name"] == "sp_t").elementAt(0)["value"] | ||
| spTCookie: auth.credentials["cookies"].where((c)=>c["name"] == "sp_t").elementAt(0)["value"], | ||
| limit: limit, |
There was a problem hiding this comment.
spTCookie is derived via auth.credentials["cookies"].where(...).elementAt(0)["value"], which will throw if the user is logged out (credentials null), cookies missing, or the sp_t cookie isn't present. This can still cause the white-screen/crash path. Consider guarding on auth.credentials/cookies and safely selecting the cookie (e.g., firstWhere(..., orElse: () => null) / first?) and returning an empty paginated response or a clear error when unavailable.
- Bumped plugin version from 0.2.2 to 0.3.0 - Updated description to reflect enhancements - Fixed .gitmodules to use HTTPS instead of SSH for hetu_spotify_gql_client - Updated submodule references Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Added _getSpTCookie() helper method with proper null checks - Added null checks for auth and credentials before making API calls - Returns empty result instead of crashing when not authenticated - Fixed optional chaining for external_urls Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fixed SpotifyGqlApi initialization with empty token
- Re-initialize endpoints when token updates
- Added proper Random import in auth.ht
- Fixed JSON parsing for API responses (handle string vs object)
- Fixed header key format ("Cookie" instead of Cookie variable)
- Added "refreshed" event to trigger token updates
- Improved error handling in credential recovery
- Added try-catch for localStorage parsing
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
This PR fixes multiple critical bugs that were causing the application to crash, turn white, or do nothing when trying to play/load songs.
Critical Bugs Fixed:
converter.ht:48fullAlbums()returnedundefinedinstead of[][]nowtrack.ht:30-31radio()when no playlist foundbrowse.ht:19spTCookieuser.ht:25savedPlaylists()used wrong variable in callbackitemsauth.ht:119-125randomBytesFromMath()had no return statementauth.ht:127-134modeparameter ingetToken()auth.ht:196refreshCredentials()album.htexportstatementEnhancements:
trackproperty)albumproperty)external_urls?.spotify)Files Modified:
src/converter/converter.htsrc/segments/auth.htsrc/segments/browse.htsrc/segments/track.htsrc/segments/user.htsrc/segments/album.htsrc/segments/artist.htsrc/segments/playlist.htsrc/segments/search.htsrc/plugin.htTest plan
Fixes #64