mirror of
https://github.com/evennia/evennia.git
synced 2026-03-20 23:06:31 +01:00
Updated how cmdsethandler reports syntaxerrors in command modules - this used to lead to rather opaque error messages. Now a dummy cmdset is created instead, with the key _ERROR_CMDSET and holding the error message. This allows the user to see that an error was reported instead of just being left in the blank. Full tracebacks are reported to log as usual.
This commit is contained in:
parent
e82ccc72ae
commit
0e42eb74ed
2 changed files with 18 additions and 11 deletions
|
|
@ -41,6 +41,7 @@ from twisted.internet.defer import inlineCallbacks, returnValue
|
|||
from django.conf import settings
|
||||
from src.comms.channelhandler import CHANNELHANDLER
|
||||
from src.utils import logger, utils
|
||||
from src.commands.cmdset import CmdSet
|
||||
from src.commands.cmdparser import at_multimatch_cmd
|
||||
from src.utils.utils import string_suggestions
|
||||
|
||||
|
|
@ -133,9 +134,11 @@ def get_and_merge_cmdsets(caller):
|
|||
except AttributeError:
|
||||
player_cmdset = None
|
||||
|
||||
cmdsets = [caller_cmdset] + [player_cmdset] + [channel_cmdset] + local_objects_cmdsets
|
||||
cmdsets = yield [caller_cmdset] + [player_cmdset] + [channel_cmdset] + local_objects_cmdsets
|
||||
# weed out all non-found sets
|
||||
cmdsets = yield [cmdset for cmdset in cmdsets if cmdset]
|
||||
# report cmdset errors to user (these should already have been logged)
|
||||
yield [caller.msg(cmdset.message) for cmdset in cmdsets if cmdset.key == "_CMDSET_ERROR"]
|
||||
# sort cmdsets after reverse priority (highest prio are merged in last)
|
||||
cmdsets = yield sorted(cmdsets, key=lambda x: x.priority)
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,11 @@ __all__ = ("import_cmdset", "CmdSetHandler")
|
|||
|
||||
_CACHED_CMDSETS = {}
|
||||
|
||||
class _ErrorCmdSet(CmdSet):
|
||||
"This is a special cmdset used to report errors"
|
||||
key = "_CMDSET_ERROR"
|
||||
message = "Error when loading cmdset."
|
||||
|
||||
def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||
"""
|
||||
This helper function is used by the cmdsethandler to load a cmdset
|
||||
|
|
@ -113,19 +118,18 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
|||
errstring = errstring % (classname, modulepath)
|
||||
raise
|
||||
except Exception:
|
||||
errstring = "\n%s\nCompile/Run error when loading cmdset '%s'."
|
||||
errstring = errstring % (traceback.format_exc(), python_path)
|
||||
errstring = "Compile/Run error when loading cmdset '%s'. Error was logged."
|
||||
errstring = errstring % (python_path)
|
||||
raise
|
||||
except Exception, e:
|
||||
if errstring and not no_logging:
|
||||
print errstring
|
||||
logger.log_trace()
|
||||
except Exception:
|
||||
# returning an empty error cmdset
|
||||
if not no_logging:
|
||||
logger.log_trace(errstring)
|
||||
if emit_to_obj and not ServerConfig.objects.conf("server_starting_mode"):
|
||||
object.__getattribute__(emit_to_obj, "msg")(errstring)
|
||||
if not errstring:
|
||||
errstring = "Error in import cmdset: %s" % e
|
||||
logger.log_errmsg(errstring)
|
||||
#cannot raise - it kills the server if no base cmdset exists!
|
||||
err_cmdset = _ErrorCmdSet()
|
||||
err_cmdset.message = errstring
|
||||
return err_cmdset
|
||||
|
||||
# classes
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue