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:
parent
2fa04162c3
commit
09b9784c3f
1 changed files with 21 additions and 4 deletions
|
|
@ -80,6 +80,8 @@ __all__ = ("import_cmdset", "CmdSetHandler")
|
||||||
_CACHED_CMDSETS = {}
|
_CACHED_CMDSETS = {}
|
||||||
_CMDSET_PATHS = utils.make_iter(settings.CMDSET_PATHS)
|
_CMDSET_PATHS = utils.make_iter(settings.CMDSET_PATHS)
|
||||||
_IN_GAME_ERRORS = settings.IN_GAME_ERRORS
|
_IN_GAME_ERRORS = settings.IN_GAME_ERRORS
|
||||||
|
_CMDSET_FALLBACKS = settings.CMDSET_FALLBACKS
|
||||||
|
|
||||||
|
|
||||||
# Output strings
|
# Output strings
|
||||||
|
|
||||||
|
|
@ -102,6 +104,16 @@ _ERROR_CMDSET_EXCEPTION = _(
|
||||||
Compile/Run error when loading cmdset '{path}'.",
|
Compile/Run error when loading cmdset '{path}'.",
|
||||||
(Traceback was logged {timestamp})""")
|
(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):
|
class _ErrorCmdSet(CmdSet):
|
||||||
"""
|
"""
|
||||||
|
|
@ -353,14 +365,19 @@ class CmdSetHandler(object):
|
||||||
if cmdset:
|
if cmdset:
|
||||||
if cmdset.key == '_CMDSET_ERROR':
|
if cmdset.key == '_CMDSET_ERROR':
|
||||||
# If a cmdset fails to load, check if we have a fallback path to use
|
# 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:
|
if fallback_path:
|
||||||
logger.log_err("Error encountered for cmdset at path %s. Replacing with: %s" % (
|
err = _ERROR_CMDSET_FALLBACK.format(path=path, fallback_path=fallback_path)
|
||||||
path, fallback_path))
|
logger.log_err(err)
|
||||||
|
if _IN_GAME_ERRORS:
|
||||||
|
self.obj.msg(err)
|
||||||
cmdset = self._import_cmdset(fallback_path)
|
cmdset = self._import_cmdset(fallback_path)
|
||||||
# If no cmdset is returned from the fallback, we can't go further
|
# If no cmdset is returned from the fallback, we can't go further
|
||||||
if not cmdset:
|
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
|
continue
|
||||||
cmdset.permanent = cmdset.key != '_CMDSET_ERROR'
|
cmdset.permanent = cmdset.key != '_CMDSET_ERROR'
|
||||||
self.cmdset_stack.append(cmdset)
|
self.cmdset_stack.append(cmdset)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue