0

changed level data loader to retry up to twice before declaring a chunk corrupt

This commit is contained in:
Aaron Griffith
2011-03-19 18:23:23 -04:00
parent ad0899bb8a
commit edf34f6d59

View File

@@ -46,15 +46,20 @@ image
# alpha_over extension, BUT this extension may fall back to PIL's # alpha_over extension, BUT this extension may fall back to PIL's
# paste(), which DOES need the workaround.) # paste(), which DOES need the workaround.)
def get_lvldata(filename, x, y): def get_lvldata(filename, x, y, retries=2):
"""Takes a filename and chunkcoords and returns the Level struct, which contains all the """Takes a filename and chunkcoords and returns the Level struct, which contains all the
level info""" level info"""
try: try:
d = nbt.load_from_region(filename, x, y) d = nbt.load_from_region(filename, x, y)
except Exception, e: except Exception, e:
logging.warning("Error opening chunk (%i, %i) in %s. It may be corrupt. %s", x, y, filename, e) if retries > 0:
raise ChunkCorrupt(str(e)) # wait a little bit, and try again (up to `retries` times)
time.sleep(1)
return get_lvldata(filename, x, y, retries=retries-1)
else:
logging.warning("Error opening chunk (%i, %i) in %s. It may be corrupt. %s", x, y, filename, e)
raise ChunkCorrupt(str(e))
if not d: raise NoSuchChunk(x,y) if not d: raise NoSuchChunk(x,y)
return d[1]['Level'] return d[1]['Level']