From 1363fa85eb7484ca36bc578ff99400bc4dca4e79 Mon Sep 17 00:00:00 2001 From: torzdf <36920800+torzdf@users.noreply.github.com> Date: Tue, 25 Aug 2020 10:25:12 +0100 Subject: [PATCH] lib.image - More information on image read errors --- lib/image.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/image.py b/lib/image.py index 58ed40c6..55a315e1 100644 --- a/lib/image.py +++ b/lib/image.py @@ -268,17 +268,19 @@ def read_image(filename, raise_error=False, with_hash=False): try: image = cv2.imread(filename) if image is None: - raise ValueError - except TypeError: + raise ValueError("Image is None") + except TypeError as err: success = False msg = "Error while reading image (TypeError): '{}'".format(filename) + msg += ". Original error message: {}".format(str(err)) logger.error(msg) if raise_error: raise Exception(msg) - except ValueError: + except ValueError as err: success = False - msg = ("Error while reading image. This is most likely caused by special characters in " - "the filename: '{}'".format(filename)) + msg = ("Error while reading image. This can be caused by special characters in the " + "filename or a corrupt image file: '{}'".format(filename)) + msg += ". Original error message: {}".format(str(err)) logger.error(msg) if raise_error: raise Exception(msg)