From 8b6ad0cecb9810691b514789b27ff288401077cc Mon Sep 17 00:00:00 2001 From: Christian Mahnke Date: Sat, 27 May 2023 17:02:49 +0200 Subject: [PATCH] Added exception handling --- src/kubi/kubi.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/kubi/kubi.py b/src/kubi/kubi.py index 05e2cf5..dc45dc0 100644 --- a/src/kubi/kubi.py +++ b/src/kubi/kubi.py @@ -55,7 +55,11 @@ def kubi(args): size = args.size elif src_names is not None: for name in src_names: - image = pyvips.Image.new_from_file(name) + try: + image = pyvips.Image.new_from_file(name) + except Exception: + print("Input file '{}' isn't readable, exiting!".format(name)) + sys.exit(1) size = max(size, int(image.width / 4)) @@ -224,7 +228,12 @@ def kubi(args): idx = idxA[f]*fac fn = args.facenames[f] if args.facenames is not None else str(f) mapim = img.mapim(idx, interpolate=interp) - mapim.write_to_file(f'{dst}_{fn}{dst_ext}', **args.co) + try: + mapim.write_to_file(f'{dst}_{fn}{dst_ext}', **args.co) + except Exception: + if 'layout' in args.co: + print("You might have missed to add the '.dz' suffix to generate image pyramids, exiting!") + sys.exit(2) else: idx = index*fac mapim = img.mapim(idx, interpolate=interp)