Some refactoring of the cmdsethandler updates. Also took the opportunity to add the in-game-error report while I was at it.

This commit is contained in:
Griatch 2017-08-13 17:17:27 +02:00
parent 2fa04162c3
commit 09b9784c3f

View file

@ -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)