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 django.conf import settings
|
||||||
from src.comms.channelhandler import CHANNELHANDLER
|
from src.comms.channelhandler import CHANNELHANDLER
|
||||||
from src.utils import logger, utils
|
from src.utils import logger, utils
|
||||||
|
from src.commands.cmdset import CmdSet
|
||||||
from src.commands.cmdparser import at_multimatch_cmd
|
from src.commands.cmdparser import at_multimatch_cmd
|
||||||
from src.utils.utils import string_suggestions
|
from src.utils.utils import string_suggestions
|
||||||
|
|
||||||
|
|
@ -133,9 +134,11 @@ def get_and_merge_cmdsets(caller):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
player_cmdset = None
|
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
|
# weed out all non-found sets
|
||||||
cmdsets = yield [cmdset for cmdset in cmdsets if cmdset]
|
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)
|
# sort cmdsets after reverse priority (highest prio are merged in last)
|
||||||
cmdsets = yield sorted(cmdsets, key=lambda x: x.priority)
|
cmdsets = yield sorted(cmdsets, key=lambda x: x.priority)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,11 @@ __all__ = ("import_cmdset", "CmdSetHandler")
|
||||||
|
|
||||||
_CACHED_CMDSETS = {}
|
_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):
|
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
|
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)
|
errstring = errstring % (classname, modulepath)
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
errstring = "\n%s\nCompile/Run error when loading cmdset '%s'."
|
errstring = "Compile/Run error when loading cmdset '%s'. Error was logged."
|
||||||
errstring = errstring % (traceback.format_exc(), python_path)
|
errstring = errstring % (python_path)
|
||||||
raise
|
raise
|
||||||
except Exception, e:
|
except Exception:
|
||||||
if errstring and not no_logging:
|
# returning an empty error cmdset
|
||||||
print errstring
|
if not no_logging:
|
||||||
logger.log_trace()
|
logger.log_trace(errstring)
|
||||||
if emit_to_obj and not ServerConfig.objects.conf("server_starting_mode"):
|
if emit_to_obj and not ServerConfig.objects.conf("server_starting_mode"):
|
||||||
object.__getattribute__(emit_to_obj, "msg")(errstring)
|
object.__getattribute__(emit_to_obj, "msg")(errstring)
|
||||||
if not errstring:
|
err_cmdset = _ErrorCmdSet()
|
||||||
errstring = "Error in import cmdset: %s" % e
|
err_cmdset.message = errstring
|
||||||
logger.log_errmsg(errstring)
|
return err_cmdset
|
||||||
#cannot raise - it kills the server if no base cmdset exists!
|
|
||||||
|
|
||||||
# classes
|
# classes
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue