diff --git a/data/src/main/kotlin/voice/data/repo/BookRepository.kt b/data/src/main/kotlin/voice/data/repo/BookRepository.kt index caa32efd24..5209c2687e 100644 --- a/data/src/main/kotlin/voice/data/repo/BookRepository.kt +++ b/data/src/main/kotlin/voice/data/repo/BookRepository.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import voice.data.Book import voice.data.BookContent +import voice.logging.core.Logger import javax.inject.Inject import javax.inject.Singleton @@ -35,7 +36,7 @@ class BookRepository return contentRepo.flow() .map { contents -> contents.filter { it.isActive } - .map { content -> + .mapNotNull { content -> content.book() } } @@ -44,7 +45,7 @@ class BookRepository suspend fun all(): List { return contentRepo.all() .filter { it.isActive } - .map { it.book() } + .mapNotNull { it.book() } } fun flow(id: Book.Id): Flow { @@ -62,12 +63,17 @@ class BookRepository contentRepo.put(updated) } - private suspend fun BookContent.book(): Book { + private suspend fun BookContent.book(): Book? { warmUp() return Book( content = this, chapters = chapters.map { chapterId -> - chapterRepo.get(chapterId)!! + val chapter = chapterRepo.get(chapterId) + if (chapter == null) { + Logger.e("Missing chapter with id=$chapterId for $this") + return null + } + chapter } ) } diff --git a/logging/core/src/main/kotlin/voice/logging/core/Logger.kt b/logging/core/src/main/kotlin/voice/logging/core/Logger.kt index 017c744ab9..4414f2fb46 100644 --- a/logging/core/src/main/kotlin/voice/logging/core/Logger.kt +++ b/logging/core/src/main/kotlin/voice/logging/core/Logger.kt @@ -25,6 +25,10 @@ object Logger { log(severity = Severity.Warn, message = message, throwable = throwable) } + fun e(message: String) { + log(severity = Severity.Error, message = message, throwable = null) + } + fun e(throwable: Throwable, message: String) { log(severity = Severity.Error, message = message, throwable = throwable) }