From 98f37bb6fff90d9a4385ceea5454f0b5146e6dee Mon Sep 17 00:00:00 2001 From: Tim Heap Date: Wed, 16 Sep 2015 20:51:21 +1000 Subject: [PATCH] Remove bare except in unnecessary try block From a comment by @gasman on #1684: > It appears the try/catch in ImageEmbedHandler was added here: 74b9f43 > > Since the rest of the commit doesn't deal with images at all, and the > commit makes it clear that the corresponding change to > MediaEmbedHandler was intended to preserve the existing 'fail > silently' behaviour in the light of the new exceptions added for media > embeds - I think this try/catch is redundant. `Format.image_to_html` > does its own catching of image IO errors, which seems to be > sufficiently robust (if it wasn't, we'd be seeing errors on front-end > page rendering), so I think this try/catch can reasonably be deleted. https://github.com/torchbox/wagtail/pull/1684#issuecomment-140695060 --- wagtail/wagtailimages/rich_text.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/wagtail/wagtailimages/rich_text.py b/wagtail/wagtailimages/rich_text.py index 9caaed3bd..17d0fcfbf 100644 --- a/wagtail/wagtailimages/rich_text.py +++ b/wagtail/wagtailimages/rich_text.py @@ -31,15 +31,12 @@ class ImageEmbedHandler(object): Image = get_image_model() try: image = Image.objects.get(id=attrs['id']) - format = get_image_format(attrs['format']) - - if for_editor: - try: - return format.image_to_editor_html(image, attrs['alt']) - except: - return '' - else: - return format.image_to_html(image, attrs['alt']) - except Image.DoesNotExist: return "" + + format = get_image_format(attrs['format']) + + if for_editor: + return format.image_to_editor_html(image, attrs['alt']) + else: + return format.image_to_html(image, attrs['alt'])