fix(android-auto): handle unhandled exceptions and empty track lists in playItem/getScreen#153
Open
shinodanpen wants to merge 1 commit intoDJDoubleD:masterfrom
Open
Conversation
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.
Description
Fixes #68 — Android Auto shows the library but tapping a track returns to the main screen without playing anything.
Root cause analysis
Static analysis identified two main failure points:
1. Unhandled exceptions in
playItem()playItem()inandroid_auto.dartmakes async Deezer API calls (fullPlaylist,album,smartTrackList) with no error handling. If any of these throw (expired token, network error, null response), the exception propagates silently through theaudio_serviceframework, which swallows it and leaves Android Auto in its previous state — causing the "returns to main screen" symptom.2. Empty track list crash
p.tracks?[0]anda.tracks?[0]are only null-guarded, not empty-guarded. If the API returns an object with an empty track list, this throws aRangeError.Changes
lib/ui/android_auto.dartplayItem()in a try-catch withLogger.root.severeloggingtracks[0]for both playlists and albumsgetScreen()in individual try-catch blocks, consistent with the existing pattern already used for thehomescreenbranchprintcalls withLogger.root.severein the_aa_tracksbranchimport 'package:logging/logging.dart'lib/service/audio_service.dart_androidAuto.playItem(mediaId)call inplayFromMediaId()with a try-catch as a safety netWhat's not included
The auth race condition in
main.dart(authorize()not awaited before Android Auto calls) was identified during analysis but is out of scope for this fix — it deserves a separate issue.Testing
Changes were developed and verified through static analysis and code review with the assistance of AI tools (Claude). Runtime testing on a physical Android Auto setup was not possible due to build environment constraints. The fix addresses all identified failure paths that match the reported symptom.