Skip to content

Commit

Permalink
Improve error handling in aspect_ratio()
Browse files Browse the repository at this point in the history
  • Loading branch information
kvid committed Aug 29, 2020
1 parent ede29cb commit 7c2fdd6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/wireviz/wv_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 7c2fdd6

Please sign in to comment.