From 7af188da4efd50a04748b3eed958046ad3014a32 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Mon, 30 Mar 2020 07:47:16 +0200 Subject: [PATCH] textures: better error logging for corrupt files Sometimes people's texture packs contain weird things, and it'd be good if instead of throwing an unhandled IOError, we raise a TextureException with the filename in it. Also, make verbose mode actually run find_file in verbose mode, which is useful for finding where Overviewer loaded that texture file from. --- overviewer_core/textures.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index 8867726..5ce7a4f 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -353,14 +353,19 @@ class Textures(object): pass try: - fileobj = self.find_file(filename) + fileobj = self.find_file(filename, verbose=logging.getLogger().isEnabledFor(logging.DEBUG)) except (TextureException, IOError) as e: # We cache when our good friend find_file can't find # a texture, so that we do not repeatedly search for it. self.texture_cache[filename] = e raise e buffer = BytesIO(fileobj.read()) - img = Image.open(buffer).convert("RGBA") + try: + img = Image.open(buffer).convert("RGBA") + except IOError: + raise TextureException("The texture {} appears to be corrupted. Please fix it. Run " + "Overviewer in verbose mode (-v) to find out where I loaded " + "that file from.".format(filename)) self.texture_cache[filename] = img return img