From 8d7a75d28f1a85d0973748832e8e25fea55acf68 Mon Sep 17 00:00:00 2001 From: Mouaad Aallam Date: Mon, 25 Jul 2022 10:19:30 +0200 Subject: [PATCH] chore(paging): add logging warning on fail (#347) --- extensions/android-loading/build.gradle.kts | 5 +---- extensions/android-paging3/build.gradle.kts | 1 - .../paging3/internal/SearcherPagingSource.kt | 22 ++++++++++--------- instantsearch-compose/build.gradle.kts | 5 +---- .../instantsearch/extension/Console.kt | 12 +++++----- .../instantsearch/extension/Console.kt | 13 ++++++----- .../instantsearch/extension/Console.kt | 14 ++++++------ 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/extensions/android-loading/build.gradle.kts b/extensions/android-loading/build.gradle.kts index 0a961f6bd..490f2d31e 100644 --- a/extensions/android-loading/build.gradle.kts +++ b/extensions/android-loading/build.gradle.kts @@ -20,10 +20,7 @@ android { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() - freeCompilerArgs += listOf( - "-Xopt-in=kotlin.RequiresOptIn", - "-Xexplicit-api=strict" - ) + freeCompilerArgs += listOf("-Xexplicit-api=strict") } buildFeatures { diff --git a/extensions/android-paging3/build.gradle.kts b/extensions/android-paging3/build.gradle.kts index a9b355b54..8c036ebe4 100644 --- a/extensions/android-paging3/build.gradle.kts +++ b/extensions/android-paging3/build.gradle.kts @@ -21,7 +21,6 @@ android { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() freeCompilerArgs += listOf( - "-Xopt-in=kotlin.RequiresOptIn", "-Xopt-in=com.algolia.instantsearch.ExperimentalInstantSearch", "-Xopt-in=com.algolia.instantsearch.InternalInstantSearch", "-Xexplicit-api=strict" diff --git a/extensions/android-paging3/src/main/kotlin/com/algolia/instantsearch/android/paging3/internal/SearcherPagingSource.kt b/extensions/android-paging3/src/main/kotlin/com/algolia/instantsearch/android/paging3/internal/SearcherPagingSource.kt index 64d99a6d4..18129f02f 100644 --- a/extensions/android-paging3/src/main/kotlin/com/algolia/instantsearch/android/paging3/internal/SearcherPagingSource.kt +++ b/extensions/android-paging3/src/main/kotlin/com/algolia/instantsearch/android/paging3/internal/SearcherPagingSource.kt @@ -2,6 +2,7 @@ package com.algolia.instantsearch.android.paging3.internal import androidx.paging.PagingSource import androidx.paging.PagingState +import com.algolia.instantsearch.extension.Console import com.algolia.instantsearch.searcher.SearcherForHits import com.algolia.search.model.params.SearchParameters import com.algolia.search.model.response.ResponseSearch @@ -35,22 +36,23 @@ internal class SearcherPagingSource( prevKey = null, // no paging backward nextKey = nextKey ) - } catch (throwable: Throwable) { - LoadResult.Error(throwable) + } catch (exception: Exception) { + Console.warn("Paging search operation failed", exception) + LoadResult.Error(exception) } } - private suspend fun search(): ResponseSearch? { + private suspend fun search(): ResponseSearch? = with(searcher) { try { - searcher.isLoading.value = true - val response = searcher.search() - searcher.response.value = response - searcher.isLoading.value = false - return response + isLoading.value = true + val searchResponse = search() + response.value = searchResponse + return searchResponse } catch (exception: Exception) { - searcher.error.value = exception - searcher.isLoading.value = false + error.value = exception throw exception + } finally { + isLoading.value = false } } diff --git a/instantsearch-compose/build.gradle.kts b/instantsearch-compose/build.gradle.kts index 4fd5bfcde..c57ef36ae 100644 --- a/instantsearch-compose/build.gradle.kts +++ b/instantsearch-compose/build.gradle.kts @@ -20,10 +20,7 @@ android { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() - freeCompilerArgs += listOf( - "-Xopt-in=kotlin.RequiresOptIn", - "-Xexplicit-api=strict" - ) + freeCompilerArgs += listOf("-Xexplicit-api=strict") } buildFeatures { diff --git a/instantsearch/src/androidMain/kotlin/com/algolia/instantsearch/extension/Console.kt b/instantsearch/src/androidMain/kotlin/com/algolia/instantsearch/extension/Console.kt index 24cf3c9a7..d3606dc00 100644 --- a/instantsearch/src/androidMain/kotlin/com/algolia/instantsearch/extension/Console.kt +++ b/instantsearch/src/androidMain/kotlin/com/algolia/instantsearch/extension/Console.kt @@ -1,24 +1,26 @@ package com.algolia.instantsearch.extension import android.util.Log +import com.algolia.instantsearch.InternalInstantSearch -internal actual object Console { +@InternalInstantSearch +public actual object Console { private const val Tag = "InstantSearch" - actual fun debug(message: String, throwable: Throwable?) { + public actual fun debug(message: String, throwable: Throwable?) { Log.d(Tag, message, throwable) } - actual fun info(message: String, throwable: Throwable?) { + public actual fun info(message: String, throwable: Throwable?) { Log.i(Tag, message, throwable) } - actual fun warn(message: String, throwable: Throwable?) { + public actual fun warn(message: String, throwable: Throwable?) { Log.w(Tag, message, throwable) } - actual fun error(message: String, throwable: Throwable?) { + public actual fun error(message: String, throwable: Throwable?) { Log.e(Tag, message, throwable) } } diff --git a/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/extension/Console.kt b/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/extension/Console.kt index e64a4ad02..947f240eb 100644 --- a/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/extension/Console.kt +++ b/instantsearch/src/commonMain/kotlin/com/algolia/instantsearch/extension/Console.kt @@ -1,12 +1,15 @@ package com.algolia.instantsearch.extension -internal expect object Console { +import com.algolia.instantsearch.InternalInstantSearch - fun debug(message: String, throwable: Throwable? = null) +@InternalInstantSearch +public expect object Console { - fun info(message: String, throwable: Throwable? = null) + public fun debug(message: String, throwable: Throwable? = null) - fun warn(message: String, throwable: Throwable? = null) + public fun info(message: String, throwable: Throwable? = null) - fun error(message: String, throwable: Throwable? = null) + public fun warn(message: String, throwable: Throwable? = null) + + public fun error(message: String, throwable: Throwable? = null) } diff --git a/instantsearch/src/jvmMain/kotlin/com/algolia/instantsearch/extension/Console.kt b/instantsearch/src/jvmMain/kotlin/com/algolia/instantsearch/extension/Console.kt index 0e09bd5cf..d82d9735a 100644 --- a/instantsearch/src/jvmMain/kotlin/com/algolia/instantsearch/extension/Console.kt +++ b/instantsearch/src/jvmMain/kotlin/com/algolia/instantsearch/extension/Console.kt @@ -1,27 +1,27 @@ package com.algolia.instantsearch.extension +import com.algolia.instantsearch.InternalInstantSearch import java.util.logging.Level import java.util.logging.Logger -internal actual object Console { +@InternalInstantSearch +public actual object Console { - private const val Tag = "InstantSearch" private val logger = Logger.getLogger(Console::class.qualifiedName) - actual fun debug(message: String, throwable: Throwable?) { + public actual fun debug(message: String, throwable: Throwable?) { logger.log(Level.FINE, message, throwable) } - actual fun info(message: String, throwable: Throwable?) { + public actual fun info(message: String, throwable: Throwable?) { logger.log(Level.INFO, message, throwable) } - actual fun warn(message: String, throwable: Throwable?) { + public actual fun warn(message: String, throwable: Throwable?) { logger.log(Level.WARNING, message, throwable) } - actual fun error(message: String, throwable: Throwable?) { + public actual fun error(message: String, throwable: Throwable?) { logger.log(Level.SEVERE, message, throwable) } - }