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: except CorruptNBTError, e:
logging.error("Failed to open world %r", render['world']) logging.error("Failed to open world %r", render['world'])
raise e raise e
except world.UnsupportedVersion, e:
for ln in str(e).split('\n'):
logging.error(ln)
sys.exit(1)
worldcache[render['world']] = w worldcache[render['world']] = w

View File

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