mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-13 09:26:52 -04:00
Merge pull request #3904 from kiwix/Fixes#3901
Fixed: A `NotSerializableException` was attached to the crash logs instead of the actual crash logs when there was an error in the coroutine.
This commit is contained in:
commit
262b4e5d75
@ -14,7 +14,7 @@ object Versions {
|
||||
|
||||
const val document_file_version: String = "1.0.1"
|
||||
|
||||
const val org_jetbrains_kotlinx_kotlinx_coroutines: String = "1.4.1"
|
||||
const val org_jetbrains_kotlinx_kotlinx_coroutines: String = "1.7.3"
|
||||
|
||||
const val androidx_test_espresso: String = "3.5.1"
|
||||
|
||||
|
@ -211,9 +211,17 @@ open class ErrorActivity : BaseActivity() {
|
||||
.getPackageInformation(packageName, ZERO).versionName
|
||||
|
||||
private fun toStackTraceString(exception: Throwable): String =
|
||||
StringWriter().apply {
|
||||
exception.printStackTrace(PrintWriter(this))
|
||||
}.toString()
|
||||
try {
|
||||
StringWriter().apply {
|
||||
exception.printStackTrace(PrintWriter(this))
|
||||
}.toString()
|
||||
} catch (ignore: Exception) {
|
||||
// Some exceptions thrown by coroutines do not have a stack trace.
|
||||
// These exceptions contain the full error message in the exception object itself.
|
||||
// To handle these cases, log the full exception message as it contains the
|
||||
// main cause of the error.
|
||||
StringWriter().append("$exception").toString()
|
||||
}
|
||||
|
||||
open fun restartApp() {
|
||||
val restartAppIntent = packageManager.getLaunchIntentForPackage(packageName)?.apply {
|
||||
|
@ -212,6 +212,7 @@ class ZimFileReader constructor(
|
||||
|
||||
fun getRandomArticleUrl(): String? = jniKiwixReader.randomEntry.path
|
||||
|
||||
@Suppress("UnreachableCode")
|
||||
fun load(uri: String): InputStream? {
|
||||
val extension = uri.substringAfterLast(".")
|
||||
if (assetExtensions.any { it == extension }) {
|
||||
|
@ -22,11 +22,10 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
import kotlinx.coroutines.channels.trySendBlocking
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
@ -86,8 +85,8 @@ class SearchViewModel @Inject constructor(
|
||||
private val _effects = Channel<SideEffect<*>>()
|
||||
val effects = _effects.receiveAsFlow()
|
||||
val actions = Channel<Action>(Channel.UNLIMITED)
|
||||
private val filter = ConflatedBroadcastChannel("")
|
||||
private val searchOrigin = ConflatedBroadcastChannel(FromWebView)
|
||||
private val filter = MutableStateFlow("")
|
||||
private val searchOrigin = MutableStateFlow(FromWebView)
|
||||
|
||||
init {
|
||||
viewModelScope.launch { reducer() }
|
||||
@ -97,10 +96,10 @@ class SearchViewModel @Inject constructor(
|
||||
@Suppress("DEPRECATION")
|
||||
private suspend fun reducer() {
|
||||
combine(
|
||||
filter.asFlow(),
|
||||
filter.asStateFlow(),
|
||||
searchResults(),
|
||||
recentSearchRoomDao.recentSearches(zimReaderContainer.id),
|
||||
searchOrigin.asFlow()
|
||||
searchOrigin.asStateFlow()
|
||||
) { searchTerm, searchResultsWithTerm, recentResults, searchOrigin ->
|
||||
SearchState(
|
||||
searchTerm, searchResultsWithTerm,
|
||||
@ -111,7 +110,7 @@ class SearchViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun searchResults() = filter.asFlow()
|
||||
private fun searchResults() = filter.asStateFlow()
|
||||
.mapLatest {
|
||||
SearchResultsWithTerm(
|
||||
it,
|
||||
@ -126,7 +125,7 @@ class SearchViewModel @Inject constructor(
|
||||
is OnItemClick -> saveSearchAndOpenItem(it.searchListItem, false)
|
||||
is OnOpenInNewTabClick -> saveSearchAndOpenItem(it.searchListItem, true)
|
||||
is OnItemLongClick -> showDeleteDialog(it)
|
||||
is Filter -> filter.trySendBlocking(it.term)
|
||||
is Filter -> filter.tryEmit(it.term)
|
||||
ClickedSearchInText -> searchPreviousScreenWhenStateIsValid()
|
||||
is ConfirmedDelete -> deleteItemAndShowToast(it)
|
||||
is CreatedWithArguments -> _effects.trySend(
|
||||
@ -148,7 +147,7 @@ class SearchViewModel @Inject constructor(
|
||||
)
|
||||
).isSuccess
|
||||
|
||||
is ScreenWasStartedFrom -> searchOrigin.trySendBlocking(it.searchOrigin)
|
||||
is ScreenWasStartedFrom -> searchOrigin.tryEmit(it.searchOrigin)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,7 @@ object ServerUtils {
|
||||
val ipRegex =
|
||||
"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
||||
.toRegex()
|
||||
val ipMatch = ipRegex.find(ip, 0) ?: throw IllegalArgumentException()
|
||||
return ipMatch.value
|
||||
return ipRegex.find(ip, 0)?.value ?: throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
@JvmStatic fun getSocketAddress(): String =
|
||||
|
Loading…
x
Reference in New Issue
Block a user