From 8814778c22fb4848e71025276bfa164bc9a919b2 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 12 Mar 2022 14:18:08 +0000 Subject: [PATCH] Add error handling on `read_page` (fixes #281) --- src/library/entry.cr | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/library/entry.cr b/src/library/entry.cr index 43cadbe..55d0062 100644 --- a/src/library/entry.cr +++ b/src/library/entry.cr @@ -144,13 +144,17 @@ class Entry def read_page(page_num) raise "Unreadble archive. #{@err_msg}" if @err_msg img = nil - sorted_archive_entries do |file, entries| - page = entries[page_num - 1] - data = file.read_entry page - if data - img = Image.new data, MIME.from_filename(page.filename), page.filename, - data.size + begin + sorted_archive_entries do |file, entries| + page = entries[page_num - 1] + data = file.read_entry page + if data + img = Image.new data, MIME.from_filename(page.filename), + page.filename, data.size + end end + rescue e + Logger.warn "Unable to read page #{page_num} of #{@zip_path}. Error: #{e}" end img end