diff --git a/kittens/icat/main.py b/kittens/icat/main.py index cc56fcea4..1c826a29a 100755 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -18,7 +18,8 @@ from kitty.constants import appname from kitty.utils import fit_image, read_with_timeout from ..tui.images import ( - NoImageMagick, OpenFailed, convert, fsenc, identify, screen_size + ConvertFailed, NoImageMagick, OpenFailed, convert, fsenc, identify, + screen_size ) from ..tui.operations import clear_images_on_screen, serialize_gr_command @@ -290,6 +291,8 @@ def main(args=sys.argv): process(item, args) except NoImageMagick as e: raise SystemExit(str(e)) + except ConvertFailed as e: + raise SystemExit(str(e)) except OpenFailed as e: errors.append(e) if args.place: diff --git a/kittens/tui/images.py b/kittens/tui/images.py index f20389bbb..fac02f969 100644 --- a/kittens/tui/images.py +++ b/kittens/tui/images.py @@ -35,6 +35,15 @@ class OpenFailed(ValueError): self.path = path +class ConvertFailed(ValueError): + + def __init__(self, path, message): + ValueError.__init__( + self, 'Failed to convert image: {} with error: {}'.format(path, message) + ) + self.path = path + + class NoImageMagick(Exception): pass @@ -57,7 +66,7 @@ def identify(path): return ImageData(parts[0].lower(), int(parts[1]), int(parts[2]), mode) -def convert(path, m, available_width, available_height, scale_up, tdir=None, err_class=SystemExit): +def convert(path, m, available_width, available_height, scale_up, tdir=None): from tempfile import NamedTemporaryFile width, height = m.width, m.height cmd = ['convert', '-background', 'none', path] @@ -78,7 +87,7 @@ def convert(path, m, available_width, available_height, scale_up, tdir=None, err if sz < expected_size: missing = expected_size - sz if missing % (bytes_per_pixel * width) != 0: - raise err_class('ImageMagick failed to convert {} correctly, it generated {} < {} of data'.format(path, sz, expected_size)) + raise ConvertFailed(path, 'ImageMagick failed to convert {} correctly, it generated {} < {} of data'.format(path, sz, expected_size)) height -= missing // (bytes_per_pixel * width) return outfile.name, width, height @@ -165,7 +174,7 @@ class ImageManager: def convert_image(self, path, available_width, available_height, image_data, scale_up=False): try: - rgba_path, width, height = convert(path, image_data, available_width, available_height, scale_up, tdir=self.tdir, exc_class=ValueError) + rgba_path, width, height = convert(path, image_data, available_width, available_height, scale_up, tdir=self.tdir) except ValueError: rgba_path = None width = height = 0