Skip to content

Commit

Permalink
FIX PKGS-1399 Set retry limit in various ViewModel classes (#141)
Browse files Browse the repository at this point in the history
This commit sets the retry attempts from default (unlimited) to 5 in several classes. The change improves error handling by preventing potential infinite loops in case of persistent failures.

Co-authored-by: Lamberto Basti <[email protected]>
  • Loading branch information
lamba92 and Lamberto Basti authored Mar 2, 2024
1 parent 0a199d6 commit 98d978d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PackageSearchFUSService(coroutineScope: CoroutineScope) {
init {
fusEventsFlow
.onEach { it.log() }
.retry {
.retry(5) {
logWarn("${this::class.qualifiedName}#eventReportingJob", it) { "Failed to log FUS" }
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.intellij.psi.PsiManager
import com.jetbrains.packagesearch.plugin.PackageSearchModuleBaseTransformerUtils
import com.jetbrains.packagesearch.plugin.core.extensions.PackageSearchKnownRepositoriesContext
import com.jetbrains.packagesearch.plugin.core.utils.IntelliJApplication
import com.jetbrains.packagesearch.plugin.core.utils.PackageSearchProjectCachesService
import com.jetbrains.packagesearch.plugin.core.utils.fileOpenedFlow
import com.jetbrains.packagesearch.plugin.core.utils.replayOn
import com.jetbrains.packagesearch.plugin.core.utils.toolWindowOpenedFlow
Expand Down Expand Up @@ -79,7 +78,7 @@ class PackageSearchProjectService(
.getKnownRepositories()
.associateBy { it.id }
}
.retry {
.retry(5) {
logWarn("${this::class.simpleName}#knownRepositoriesStateFlow", throwable = it)
true
}
Expand Down Expand Up @@ -169,7 +168,7 @@ class PackageSearchProjectService(
.filter { it }
.throttle(30.minutes)
.onEach { restart() }
.retry {
.retry(5) {
logWarn("${this::class.simpleName}#isOnlineFlow", throwable = it)
true
}
Expand All @@ -188,7 +187,7 @@ class PackageSearchProjectService(
?.let { DaemonCodeAnalyzer.getInstance(project).restart(it) }
}
}
.retry {
.retry(5) {
logWarn("${this::class.simpleName}#fileOpenedFlow", throwable = it)
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ToolWindowViewModel(project: Project, private val viewModelScope: Coroutin
else -> PackageSearchToolWindowState.NoModules
}
}
.retry()
.retry(5)
.stateIn(
scope = viewModelScope,
started = SharingStarted.Lazily,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class InfoPanelViewModel(
}
}
}
.retry()
.retry(5)
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())

private val activeTabTitleMutableStateFlow: MutableStateFlow<String?> = MutableStateFlow(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class PackageListViewModel(
current
}
}
.retry()
.retry(5)
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyMap())

val selectableLazyListState = SelectableLazyListState(LazyListState())
Expand Down Expand Up @@ -202,7 +202,7 @@ class PackageListViewModel(
}
}
}
.retry()
.retry(5)
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), emptyList())

private suspend fun PackageSearchModule.Base.getSearchQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class TreeViewModel(
) { modules, stableOnly ->
modules.asTree(stableOnly)
}
.retry()
.retry(5)
.onEach { logDebug("${this::class.qualifiedName}#treeStateFlow") { it.print() } }
.stateIn(viewModelScope, SharingStarted.Lazily, emptyTree())

Expand Down

0 comments on commit 98d978d

Please sign in to comment.