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:
@@ -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())
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user