From 7c2fdd6d5ab888dfd63bbc3ece5ab99d489fb15c Mon Sep 17 00:00:00 2001 From: KV Date: Sat, 29 Aug 2020 20:47:11 +0200 Subject: [PATCH] Improve error handling in aspect_ratio() --- src/wireviz/wv_helper.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 5535ce7..32b8fb6 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -165,11 +165,10 @@ def aspect_ratio(image_src): image = Image.open(image_src) if image.width > 0 and image.height > 0: return image.width / image.height - print(f'aspect_ratio(): image size is {image.width} x {image.height}') - except ModuleNotFoundError as error: - print(f'aspect_ratio(): {error}') - except FileNotFoundError as error: - print(f'aspect_ratio(): {error}') + print(f'aspect_ratio(): Invalid image size {image.width} x {image.height}') + # ModuleNotFoundError and FileNotFoundError are the most expected, but all are handled equally. + except Exception as error: + print(f'aspect_ratio(): {type(error).__name__}: {error}') return 1 # Assume 1:1 when unable to read actual image size