From 09b9784c3f703ed7efe1eb36d4f8d4306dd48763 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 13 Aug 2017 17:17:27 +0200 Subject: [PATCH] Some refactoring of the cmdsethandler updates. Also took the opportunity to add the in-game-error report while I was at it. --- evennia/commands/cmdsethandler.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/evennia/commands/cmdsethandler.py b/evennia/commands/cmdsethandler.py index 3ecbd8bd36..b52c70d3a8 100644 --- a/evennia/commands/cmdsethandler.py +++ b/evennia/commands/cmdsethandler.py @@ -80,6 +80,8 @@ __all__ = ("import_cmdset", "CmdSetHandler") _CACHED_CMDSETS = {} _CMDSET_PATHS = utils.make_iter(settings.CMDSET_PATHS) _IN_GAME_ERRORS = settings.IN_GAME_ERRORS +_CMDSET_FALLBACKS = settings.CMDSET_FALLBACKS + # Output strings @@ -102,6 +104,16 @@ _ERROR_CMDSET_EXCEPTION = _( Compile/Run error when loading cmdset '{path}'.", (Traceback was logged {timestamp})""") +_ERROR_CMDSET_FALLBACK = _( +""" +Error encountered for cmdset at path '{path}'. +Replacing with fallback '{fallback_path}'. +""") + +_ERROR_CMDSET_NO_FALLBACK = _( +"""Fallback path '{fallback_path}' failed to generate a cmdset.""" +) + class _ErrorCmdSet(CmdSet): """ @@ -353,14 +365,19 @@ class CmdSetHandler(object): if cmdset: if cmdset.key == '_CMDSET_ERROR': # If a cmdset fails to load, check if we have a fallback path to use - fallback_path = settings.CMDSET_FALLBACKS.get(path, None) + fallback_path = _CMDSET_FALLBACKS.get(path, None) if fallback_path: - logger.log_err("Error encountered for cmdset at path %s. Replacing with: %s" % ( - path, fallback_path)) + err = _ERROR_CMDSET_FALLBACK.format(path=path, fallback_path=fallback_path) + logger.log_err(err) + if _IN_GAME_ERRORS: + self.obj.msg(err) cmdset = self._import_cmdset(fallback_path) # If no cmdset is returned from the fallback, we can't go further if not cmdset: - logger.log_err("Fallback path '%s' failed to generate a cmdset." % fallback_path) + err = _ERROR_CMDSET_NO_FALLBACK.format(fallback_path=fallback_path) + logger.log_err(err) + if _IN_GAME_ERRORS: + self.obj.msg(err) continue cmdset.permanent = cmdset.key != '_CMDSET_ERROR' self.cmdset_stack.append(cmdset)