0

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.
This commit is contained in:
Nicolas F
2020-03-30 07:47:16 +02:00
parent e5ec41fcf9
commit 7af188da4e

View File

@@ -353,14 +353,19 @@ class Textures(object):
pass pass
try: try:
fileobj = self.find_file(filename) fileobj = self.find_file(filename, verbose=logging.getLogger().isEnabledFor(logging.DEBUG))
except (TextureException, IOError) as e: except (TextureException, IOError) as e:
# We cache when our good friend find_file can't find # We cache when our good friend find_file can't find
# a texture, so that we do not repeatedly search for it. # a texture, so that we do not repeatedly search for it.
self.texture_cache[filename] = e self.texture_cache[filename] = e
raise e raise e
buffer = BytesIO(fileobj.read()) buffer = BytesIO(fileobj.read())
try:
img = Image.open(buffer).convert("RGBA") 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 self.texture_cache[filename] = img
return img return img