From 920733075bf507482bf7cea29d94f55cfde4c30e Mon Sep 17 00:00:00 2001 From: Ray <154766448+damontecres@users.noreply.github.com> Date: Sat, 21 Mar 2026 19:17:43 -0400 Subject: [PATCH] Better error handling for errors on home page rows (#1128) ## Description Adds better error handling when loading home page rows. For example, this fixes loading errors if a playlist row is configured, but the playlist is deleted. Also fixes an issue from #1116 where changing users doesn't go the home page. ### Related issues Related to #1124 ### Testing Emulator ## Screenshots N/A ## AI or LLM usage None --- .../wholphin/services/HomeSettingsService.kt | 35 ++++++++----------- .../wholphin/services/NavigationManager.kt | 3 +- .../services/SetupNavigationManager.kt | 7 +++- .../ui/main/settings/HomeSettingsViewModel.kt | 31 ++++++++++------ 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt index b8a850ef..b28dded4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/HomeSettingsService.kt @@ -438,10 +438,7 @@ class HomeSettingsService ): HomeRowConfigDisplay = when (config) { is HomeRowConfig.ByParent -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" + val name = getItemName(config.parentId) ?: "" HomeRowConfigDisplay( id, name, @@ -466,10 +463,7 @@ class HomeSettingsService } is HomeRowConfig.Genres -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" + val name = getItemName(config.parentId) ?: "" HomeRowConfigDisplay( id, context.getString(R.string.genres_in, name), @@ -490,10 +484,7 @@ class HomeSettingsService } is HomeRowConfig.RecentlyAdded -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" + val name = getItemName(config.parentId) ?: "" HomeRowConfigDisplay( id, context.getString(R.string.recently_added_in, name), @@ -502,10 +493,7 @@ class HomeSettingsService } is HomeRowConfig.RecentlyReleased -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" + val name = getItemName(config.parentId) ?: "" HomeRowConfigDisplay( id, context.getString(R.string.recently_released_in, name), @@ -547,10 +535,7 @@ class HomeSettingsService } is HomeRowConfig.Suggestions -> { - val name = - api.userLibraryApi - .getItem(itemId = config.parentId) - .content.name ?: "" + val name = getItemName(config.parentId) ?: "" HomeRowConfigDisplay( id = id, title = context.getString(R.string.suggestions_for, name), @@ -559,6 +544,16 @@ class HomeSettingsService } } + private suspend fun getItemName(itemId: UUID): String? = + try { + api.userLibraryApi + .getItem(itemId = itemId) + .content.name + } catch (ex: Exception) { + Timber.e(ex, "Could not get name for %s", itemId) + context.getString(R.string.unknown) + } + /** * Fetch the data from the server for a given [HomeRowConfig] */ diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/NavigationManager.kt b/app/src/main/java/com/github/damontecres/wholphin/services/NavigationManager.kt index 1706ba52..3208f4ec 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/NavigationManager.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/NavigationManager.kt @@ -1,5 +1,6 @@ package com.github.damontecres.wholphin.services +import androidx.navigation3.runtime.NavBackStack import com.github.damontecres.wholphin.ui.nav.Destination import org.acra.ACRA import timber.log.Timber @@ -13,7 +14,7 @@ import javax.inject.Singleton class NavigationManager @Inject constructor() { - var backStack: MutableList = mutableListOf() + var backStack: MutableList = NavBackStack(Destination.Home()) /** * Go to the specified [com.github.damontecres.wholphin.ui.nav.Destination] diff --git a/app/src/main/java/com/github/damontecres/wholphin/services/SetupNavigationManager.kt b/app/src/main/java/com/github/damontecres/wholphin/services/SetupNavigationManager.kt index e4910031..fa42469e 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/services/SetupNavigationManager.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/services/SetupNavigationManager.kt @@ -16,7 +16,9 @@ import javax.inject.Singleton @Singleton class SetupNavigationManager @Inject - constructor() { + constructor( + private val navigationManager: NavigationManager, + ) { var backStack: MutableList = mutableStateListOf(SetupDestination.Loading) /** @@ -25,6 +27,9 @@ class SetupNavigationManager fun navigateTo(destination: SetupDestination) { backStack[0] = destination log() + if (destination !is SetupDestination.AppContent) { + navigationManager.reloadHome() + } } private fun log() { diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt index 67b57e28..4d2864aa 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/main/settings/HomeSettingsViewModel.kt @@ -122,19 +122,23 @@ class HomeSettingsViewModel state.value .let { state -> state.rows - .map { it.config } .map { row -> viewModelScope.async(Dispatchers.IO) { semaphore.withPermit { - homeSettingsService.fetchDataForRow( - row = row, - scope = viewModelScope, - prefs = prefs, - userDto = userDto, - libraries = state.libraries, - limit = limit, - isRefresh = false, - ) + try { + homeSettingsService.fetchDataForRow( + row = row.config, + scope = viewModelScope, + prefs = prefs, + userDto = userDto, + libraries = state.libraries, + limit = limit, + isRefresh = false, + ) + } catch (ex: Exception) { + Timber.e(ex, "Error on row %s", row) + HomeRowLoadingState.Error(row.title, exception = ex) + } } } } @@ -195,7 +199,12 @@ class HomeSettingsViewModel viewModelScope.launchIO { updateState { val rows = it.rows.toMutableList().apply { removeAt(index) } - val rowData = it.rowData.toMutableList().apply { removeAt(index) } + val rowData = + if (index in it.rowData.indices) { + it.rowData.toMutableList().apply { removeAt(index) } + } else { + it.rowData + } it.copy( rows = rows, rowData = rowData,