diff --git a/app/src/dev/java/exh/log/CrashlyticsPrinter.kt b/app/src/dev/java/exh/log/CrashlyticsPrinter.kt index 6fe782020a..47435e1ac7 100644 --- a/app/src/dev/java/exh/log/CrashlyticsPrinter.kt +++ b/app/src/dev/java/exh/log/CrashlyticsPrinter.kt @@ -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 + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 04b04bf139..7b34aa5c84 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -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 @@ -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 { @@ -1164,8 +1163,8 @@ class MangaScreenModel( } } } - } catch (e: Exception) { - exceptionHandler(e) + } catch (e: Throwable) { + relatedMangaExceptionHandler(e) } finally { if (onFinish != null) { onFinish() diff --git a/app/src/standard/java/exh/log/CrashlyticsPrinter.kt b/app/src/standard/java/exh/log/CrashlyticsPrinter.kt index 2b481ed75a..93c0b2fd84 100644 --- a/app/src/standard/java/exh/log/CrashlyticsPrinter.kt +++ b/app/src/standard/java/exh/log/CrashlyticsPrinter.kt @@ -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 + } + } + } } diff --git a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt index 081e6c0eda..7b4da496f3 100644 --- a/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt +++ b/source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt @@ -1,6 +1,5 @@ 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 @@ -8,8 +7,6 @@ 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. @@ -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", + ) } } @@ -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", + ) } } }