From a920e2bb9e9e02f25d7bab5ff67f95b82e14922b Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Tue, 4 Apr 2023 18:37:49 +0200 Subject: [PATCH] Cancelling coroutines operations such as authentication no longer displays an errors as it's something intentional --- .../kotlin/com/jetpackduba/gitnuro/git/TabState.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt index de4e4b9..08eb25a 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/TabState.kt @@ -78,7 +78,9 @@ class TabState @Inject constructor( refreshEvenIfCrashesInteractiveResult = refreshEvenIfCrashesInteractive?.invoke(ex) ?: false - if (showError) + val containsCancellation = exceptionContainsCancellation(ex) + + if (showError && !containsCancellation) errorsManager.addError(newErrorNow(ex, ex.message.orEmpty())) } finally { _processing.value = false @@ -91,6 +93,15 @@ class TabState @Inject constructor( } + private fun exceptionContainsCancellation(ex: Throwable?): Boolean { + return when (ex) { + null -> false + ex.cause -> false + is CancellationException -> true + else -> exceptionContainsCancellation(ex.cause) + } + } + fun safeProcessingWithoutGit(showError: Boolean = true, callback: suspend CoroutineScope.() -> Unit) = scope.launch(Dispatchers.IO) { _processing.value = true