Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report exception on related manga #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/dev/java/exh/log/CrashlyticsPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ class CrashlyticsPrinter(private val logLevel: Int) : Printer {
* @param msg the msg of log
*/
override fun println(logLevel: Int, tag: String?, msg: String?) = Unit

companion object {
fun reportNonFatal(e: Exception) = Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ import eu.kanade.tachiyomi.util.system.getBitmapOrNull
import eu.kanade.tachiyomi.util.system.toast
import exh.debug.DebugToggles
import exh.eh.EHentaiUpdateHelper
import exh.log.CrashlyticsPrinter.Companion.reportNonFatal
import exh.log.xLogD
import exh.log.xLogE
import exh.md.utils.FollowStatus
import exh.metadata.metadata.RaisedSearchMetadata
import exh.metadata.metadata.base.FlatMetadata
Expand Down Expand Up @@ -1133,20 +1135,17 @@ class MangaScreenModel(
// start fetching related mangas
setRelatedMangasFetchedStatus(false)

fun exceptionHandler(e: Throwable) {
logcat(LogPriority.ERROR, e)
fun relatedMangaExceptionHandler(e: Throwable) {
val message = with(context) { e.formattedMessage }

screenModelScope.launch {
snackbarHostState.showSnackbar(message = message)
}
xLogE(message)
reportNonFatal(e)
}
val state = successState ?: return
val relatedMangasEnabled = sourcePreferences.relatedMangas().get()

try {
if (state.source !is StubSource && relatedMangasEnabled) {
state.source.getRelatedMangaList(state.manga.toSManga(), { e -> exceptionHandler(e) }) { pair, _ ->
state.source.getRelatedMangaList(state.manga.toSManga(), { e -> relatedMangaExceptionHandler(e) }) { pair, _ ->
/* Push found related mangas into collection */
val relatedManga = RelatedManga.Success.fromPair(pair) { mangaList ->
mangaList.map {
Expand All @@ -1164,8 +1163,8 @@ class MangaScreenModel(
}
}
}
} catch (e: Exception) {
exceptionHandler(e)
} catch (e: Throwable) {
relatedMangaExceptionHandler(e)
} finally {
if (onFinish != null) {
onFinish()
Expand Down
11 changes: 11 additions & 0 deletions app/src/standard/java/exh/log/CrashlyticsPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ class CrashlyticsPrinter(private val logLevel: Int) : Printer {
}
}
}

companion object {
fun reportNonFatal(e: Throwable) {
try {
Firebase.crashlytics.recordException(e)
} catch (t: Throwable) {
// Crash in debug if shit like this happens
if (BuildConfig.DEBUG) throw t
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package eu.kanade.tachiyomi.source

import dev.icerock.moko.graphics.BuildConfig
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope
import logcat.LogPriority
import tachiyomi.core.common.util.system.logcat

/**
* A basic interface for creating a source. It could be an online source, a local source, etc.
Expand Down Expand Up @@ -125,15 +122,9 @@ interface CatalogueSource : Source {
runCatching { fetchRelatedMangaList(manga) }
.onSuccess { if (it.isNotEmpty()) pushResults(Pair("", it), false) }
.onFailure { e ->
@Suppress("KotlinConstantConditions")
if (BuildConfig.BUILD_TYPE == "release") {
logcat(LogPriority.ERROR, e) { "## getRelatedMangaListByExtension: $e" }
} else {
throw UnsupportedOperationException(
"Extension doesn't support site's related entries," +
" please report an issue to Komikku.",
)
}
throw Exception(
"Extension '$name' - getRelatedMangaListByExtension.\n$e",
)
}
}

Expand Down Expand Up @@ -200,7 +191,9 @@ interface CatalogueSource : Source {
}
.onSuccess { if (it.isNotEmpty()) pushResults(Pair(keyword, it), false) }
.onFailure { e ->
logcat(LogPriority.ERROR, e) { "## getRelatedMangaListBySearch: $e" }
throw Exception(
"Extension '$name' - getRelatedMangaListBySearch.\n$e",
)
}
}
}
Expand Down
Loading