From 117055bf641d6b1a03ce9998f3171fdfead8b05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ball=C3=B3=20Gy=C3=B6rgy?= Date: Sat, 2 Nov 2024 15:48:31 +0100 Subject: [PATCH] Handle more error types when opening/saving images with PIL Decoding/encoding errors sometimes raise an OSError or ValueError. --- cartridges/details_dialog.py | 2 +- cartridges/utils/save_cover.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cartridges/details_dialog.py b/cartridges/details_dialog.py index 98c27d5a..0677199e 100644 --- a/cartridges/details_dialog.py +++ b/cartridges/details_dialog.py @@ -302,7 +302,7 @@ def thread_func() -> None: with Image.open(path) as image: if getattr(image, "is_animated", False): new_path = convert_cover(path) - except UnidentifiedImageError: + except (UnidentifiedImageError, OSError, ValueError): pass if new_path: diff --git a/cartridges/utils/save_cover.py b/cartridges/utils/save_cover.py index ac3fb92a..29d2d849 100644 --- a/cartridges/utils/save_cover.py +++ b/cartridges/utils/save_cover.py @@ -63,7 +63,7 @@ def convert_cover( if shared.schema.get_boolean("high-quality-images") else shared.TIFF_COMPRESSION, ) - except UnidentifiedImageError: + except (UnidentifiedImageError, OSError, ValueError): try: Gdk.Texture.new_from_filename(str(cover_path)).save_to_tiff( tmp_path := Gio.File.new_tmp("XXXXXX.tiff")[0].get_path()