From fd19f6bf7d1ab3252d2a27c6e45d89fa613a9a8e Mon Sep 17 00:00:00 2001 From: nyne Date: Sun, 23 Feb 2025 20:24:43 +0800 Subject: [PATCH] Fixed crash caused by empty chapter list. --- lib/foundation/comic_source/models.dart | 4 +++- lib/utils/cbz.dart | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/foundation/comic_source/models.dart b/lib/foundation/comic_source/models.dart index c80fea0..2ecc171 100644 --- a/lib/foundation/comic_source/models.dart +++ b/lib/foundation/comic_source/models.dart @@ -336,8 +336,10 @@ class ComicChapters { } if (chapters.isNotEmpty) { return ComicChapters(chapters); - } else { + } else if (groupedChapters.isNotEmpty) { return ComicChapters.grouped(groupedChapters); + } else { + throw ArgumentError("Empty chapter list"); } } diff --git a/lib/utils/cbz.dart b/lib/utils/cbz.dart index dcd68d0..4710421 100644 --- a/lib/utils/cbz.dart +++ b/lib/utils/cbz.dart @@ -177,7 +177,7 @@ abstract class CBZ { tags: metaData.tags, comicType: ComicType.local, directory: dest.name, - chapters: ComicChapters.fromJson(cpMap), + chapters: ComicChapters.fromJsonOrNull(cpMap), downloadedChapters: cpMap?.keys.toList() ?? [], cover: 'cover.${coverFile.extension}', createdAt: DateTime.now(),