0

world: Don't call sys.exit here, raise something

A world being unsupported may not be a fatal application error in
all instances where this codepath in world.py is used, hence
throwing an exception is more sensible.
This commit is contained in:
Nicolas F
2018-05-09 14:25:05 +02:00
parent b9be8f8ffd
commit ebdc4016d7
2 changed files with 19 additions and 7 deletions

View File

@@ -470,6 +470,10 @@ dir but you forgot to put quotes around the directory, since it contains spaces.
except CorruptNBTError, e:
logging.error("Failed to open world %r", render['world'])
raise e
except world.UnsupportedVersion, e:
for ln in str(e).split('\n'):
logging.error(ln)
sys.exit(1)
worldcache[render['world']] = w

View File

@@ -21,7 +21,6 @@ import time
import random
import re
import locale
import sys
import numpy
@@ -36,6 +35,11 @@ This module has routines for extracting information about available worlds
class ChunkDoesntExist(Exception):
pass
class UnsupportedVersion(Exception):
pass
def log_other_exceptions(func):
"""A decorator that prints out any errors that are not
ChunkDoesntExist errors. This should decorate any functions or
@@ -109,18 +113,22 @@ class World(object):
logging.debug("Note: Allowing a version of zero in level.dat!")
## XXX temporary fix for #1194
else:
logging.critical("Sorry, This version of Minecraft-Overviewer only works with the 'Anvil' chunk format")
raise ValueError("World at %s is not compatible with Overviewer" % self.worlddir)
raise UnsupportedVersion(
("Sorry, This version of Minecraft-Overviewer only works "
"with the 'Anvil' chunk format\n"
"World at %s is not compatible with Overviewer")
% self.worlddir)
# Check for versions of minecraft after the 17w47a changes
if 'Version' in data:
version = int(data['Version']["Id"])
if version >= 1452:
logging.critical("Sorry, This version of Minecraft-Overviewer only works with versions of Minecraft 1.12 and under")
logging.critical("This is due to a change in the map chunk format that happened in snapshot 17w47a")
sys.exit(1)
raise UnsupportedVersion(
"Sorry, This version of Minecraft-Overviewer only works "
"with versions of Minecraft 1.12 and under\n"
"This is due to a change in the map chunk format that "
"happened in snapshot 17w47a")
# This isn't much data, around 15 keys and values for vanilla worlds.
self.leveldat = data