Skip to content

fix: resolve crashes and white screen when playing/loading songs - #65

Open
ujjawalkaushik1110 wants to merge 4 commits into
sonic-liberation:mainfrom
ujjawalkaushik1110:fix/crash-white-screen-bugs
Open

fix: resolve crashes and white screen when playing/loading songs#65
ujjawalkaushik1110 wants to merge 4 commits into
sonic-liberation:mainfrom
ujjawalkaushik1110:fix/crash-white-screen-bugs

Conversation

@ujjawalkaushik1110

@ujjawalkaushik1110 ujjawalkaushik1110 commented Mar 21, 2026

Copy link
Copy Markdown

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:

File Bug Fix
converter.ht:48 fullAlbums() returned undefined instead of [] Returns [] now
track.ht:30-31 Null pointer crash in radio() when no playlist found Added null check
browse.ht:19 Syntax error - missing comma after spTCookie Added comma
user.ht:25 savedPlaylists() used wrong variable in callback Fixed to use items
auth.ht:119-125 randomBytesFromMath() had no return statement Added return
auth.ht:127-134 Duplicate mode parameter in getToken() Removed duplicate
auth.ht:196 Null pointer when credentials null in refreshCredentials() Added null check
album.ht Missing export statement Added export

Enhancements:

  • Comprehensive null safety across all converter functions
  • Null checks for all endpoint functions (getTrack, getAlbum, getArtist, etc.)
  • Graceful fallbacks - functions now return empty arrays/objects instead of crashing
  • Fixed track extraction from playlist/saved items (wrapped in objects with track property)
  • Fixed album extraction from saved albums (wrapped with album property)
  • Optional chaining for nested property access (external_urls?.spotify)
  • Default values for missing fields ("Unknown Track", "Unknown Artist", etc.)
  • Improved main plugin initialization with proper auth callback

Files Modified:

  • src/converter/converter.ht
  • src/segments/auth.ht
  • src/segments/browse.ht
  • src/segments/track.ht
  • src/segments/user.ht
  • src/segments/album.ht
  • src/segments/artist.ht
  • src/segments/playlist.ht
  • src/segments/search.ht
  • src/plugin.ht

Test plan

  • Test playing a song from search results
  • Test loading user's saved tracks
  • Test loading user's saved playlists
  • Test loading user's saved albums
  • Test browsing home sections
  • Test track radio functionality
  • Verify no crashes or white screens occur

Fixes #64

## 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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of undefined).
  • Improved auth/token wiring so the API access token is refreshed into SpotifyGqlApi on 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.

Comment thread src/segments/browse.ht
Comment on lines 62 to 66
return client.browse.homeSection(
id,
id,
timeZone: timeZone,
spTCookie: auth.credentials["cookies"].where((c)=>c["name"] == "sp_t").elementAt(0)["value"],
offset: offset,

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/segments/browse.ht
Comment on lines 17 to 20
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,

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
ujjawalkaushik1110 and others added 3 commits March 21, 2026 10:15
- 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>
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.

songs can't be played or downloaded anymore | application crashes

2 participants