From ebdc4016d7dacb28db0c47cd853f0e3791a412ca Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Wed, 9 May 2018 14:25:05 +0200 Subject: [PATCH] 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. --- overviewer.py | 4 ++++ overviewer_core/world.py | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/overviewer.py b/overviewer.py index e0639e4..cbb328c 100755 --- a/overviewer.py +++ b/overviewer.py @@ -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 diff --git a/overviewer_core/world.py b/overviewer_core/world.py index 50ef898..d012d32 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -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