Catching exceptions if any thrown by this method since we are throwing the error when there are corrupted database error and other type of error while getting the searchResult from libzim.

* Fixed the library version issue.
This commit is contained in:
MohitMaliFtechiz 2024-07-09 22:12:57 +05:30
parent c969695139
commit 2d96cde064
2 changed files with 25 additions and 16 deletions

View File

@ -66,7 +66,7 @@ object Versions {
const val assertj_core: String = "3.25.3"
const val core_testing: String = "2.2.1"
const val core_testing: String = "2.2.0"
const val fragment_ktx: String = "1.2.5"
@ -86,7 +86,7 @@ object Versions {
const val core_ktx: String = "1.9.0"
const val libkiwix: String = "2.2.0"
const val libkiwix: String = "2.2.1"
const val material: String = "1.8.0"

View File

@ -22,6 +22,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem
import org.kiwix.kiwixmobile.core.utils.files.Log
data class SearchState(
val searchTerm: String,
@ -40,6 +41,7 @@ data class SearchState(
searchResultsWithTerm.searchMutex.withLock {
searchResultsWithTerm.suggestionSearch?.also { yield() }?.let {
val searchResults = mutableListOf<SearchListItem.RecentSearchListItem>()
try {
if (job?.isActive == false) {
// if the previous job is cancel then do not execute the code
return@getVisibleResults searchResults
@ -58,6 +60,13 @@ data class SearchState(
val entry = searchIterator.next()
searchResults.add(SearchListItem.RecentSearchListItem(entry.title, entry.path))
}
} catch (ignore: Exception) {
Log.e(
"SearchState",
"Could not get the searched result for searchTerm $searchTerm\n" +
"Original exception = $ignore"
)
}
/**
* Returns null if there are no suggestions left in the iterator.
* We check this in SearchFragment to avoid unnecessary data loading