From 17109ab7606724dee83981b7b8605fc2d22ef57c Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 29 Jan 2021 22:14:17 -0500 Subject: [PATCH] Handle failures when updating metadata in library updater --- .../data/library/LibraryUpdateService.kt | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index d7f3384dc1..d337834d1f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -27,7 +27,6 @@ import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.util.chapter.NoChaptersException import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource -import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.prepUpdateCover import eu.kanade.tachiyomi.util.shouldDownloadNewChapters import eu.kanade.tachiyomi.util.storage.getUriCompat @@ -38,7 +37,6 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.async @@ -333,23 +331,21 @@ class LibraryUpdateService( // Update manga details metadata in the background if (preferences.autoUpdateMetadata()) { - GlobalScope.launchIO { - try { - val updatedManga = source.getMangaDetails(manga.toMangaInfo()) - val sManga = updatedManga.toSManga() - // Avoid "losing" existing cover - if (!sManga.thumbnail_url.isNullOrEmpty()) { - manga.prepUpdateCover(coverCache, sManga, false) - } else { - sManga.thumbnail_url = manga.thumbnail_url - } - - manga.copyFrom(sManga) - db.insertManga(manga).executeAsBlocking() - } catch (e: Throwable) { - // Ignore errors and continue - Timber.e(e) + val handler = CoroutineExceptionHandler { _, exception -> + Timber.e(exception) + } + ioScope.launch(handler) { + val updatedManga = source.getMangaDetails(manga.toMangaInfo()) + val sManga = updatedManga.toSManga() + // Avoid "losing" existing cover + if (!sManga.thumbnail_url.isNullOrEmpty()) { + manga.prepUpdateCover(coverCache, sManga, false) + } else { + sManga.thumbnail_url = manga.thumbnail_url } + + manga.copyFrom(sManga) + db.insertManga(manga).executeAsBlocking() } }