Add info about the call string to the log when reporting command errors.
This commit is contained in:
parent
8254a24689
commit
4d14625504
1 changed files with 19 additions and 14 deletions
|
|
@ -166,11 +166,14 @@ class ExecSystemCommand(Exception):
|
||||||
|
|
||||||
class ErrorReported(Exception):
|
class ErrorReported(Exception):
|
||||||
"Re-raised when a subsructure already reported the error"
|
"Re-raised when a subsructure already reported the error"
|
||||||
|
def __init__(self, raw_string):
|
||||||
|
self.args = (raw_string,)
|
||||||
|
self.raw_string = raw_string
|
||||||
|
|
||||||
# Helper function
|
# Helper function
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def get_and_merge_cmdsets(caller, session, player, obj, callertype):
|
def get_and_merge_cmdsets(caller, session, player, obj, callertype, raw_string):
|
||||||
"""
|
"""
|
||||||
Gather all relevant cmdsets and merge them.
|
Gather all relevant cmdsets and merge them.
|
||||||
|
|
||||||
|
|
@ -185,6 +188,7 @@ def get_and_merge_cmdsets(caller, session, player, obj, callertype):
|
||||||
obj (Object or None): The Object associated with caller, if any.
|
obj (Object or None): The Object associated with caller, if any.
|
||||||
callertype (str): This identifies caller as either "player", "object" or "session"
|
callertype (str): This identifies caller as either "player", "object" or "session"
|
||||||
to avoid having to do this check internally.
|
to avoid having to do this check internally.
|
||||||
|
raw_string (str): The input string. This is only used for error reporting.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
cmdset (Deferred): This deferred fires with the merged cmdset
|
cmdset (Deferred): This deferred fires with the merged cmdset
|
||||||
|
|
@ -208,7 +212,7 @@ def get_and_merge_cmdsets(caller, session, player, obj, callertype):
|
||||||
returnValue([channel_cmdset])
|
returnValue([channel_cmdset])
|
||||||
except Exception:
|
except Exception:
|
||||||
_msg_err(caller, _ERROR_CMDSETS)
|
_msg_err(caller, _ERROR_CMDSETS)
|
||||||
raise ErrorReported
|
raise ErrorReported(raw_string)
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def _get_local_obj_cmdsets(obj):
|
def _get_local_obj_cmdsets(obj):
|
||||||
|
|
@ -252,7 +256,7 @@ def get_and_merge_cmdsets(caller, session, player, obj, callertype):
|
||||||
returnValue(local_obj_cmdsets)
|
returnValue(local_obj_cmdsets)
|
||||||
except Exception:
|
except Exception:
|
||||||
_msg_err(caller, _ERROR_CMDSETS)
|
_msg_err(caller, _ERROR_CMDSETS)
|
||||||
raise ErrorReported
|
raise ErrorReported(raw_string)
|
||||||
|
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
|
|
@ -265,7 +269,7 @@ def get_and_merge_cmdsets(caller, session, player, obj, callertype):
|
||||||
yield obj.at_cmdset_get()
|
yield obj.at_cmdset_get()
|
||||||
except Exception:
|
except Exception:
|
||||||
_msg_err(caller, _ERROR_CMDSETS)
|
_msg_err(caller, _ERROR_CMDSETS)
|
||||||
raise ErrorReported
|
raise ErrorReported(raw_string)
|
||||||
try:
|
try:
|
||||||
returnValue((obj.cmdset.current, list(obj.cmdset.cmdset_stack)))
|
returnValue((obj.cmdset.current, list(obj.cmdset.cmdset_stack)))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
@ -424,16 +428,17 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
def _run_command(cmd, cmdname, args):
|
def _run_command(cmd, cmdname, args, raw_string):
|
||||||
"""
|
"""
|
||||||
Helper function: This initializes and runs the Command
|
Helper function: This initializes and runs the Command
|
||||||
instance once the parser has identified it as either a normal
|
instance once the parser has identified it as either a normal
|
||||||
command or one of the system commands.
|
command or one of the system commands.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmd (Command): command object
|
cmd (Command): Command object
|
||||||
cmdname (str): name of command
|
cmdname (str): Name of command
|
||||||
args (str): extra text entered after the identified command
|
args (str): Extra text entered after the identified command
|
||||||
|
raw_string (str): Full input string, only used for debugging.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
deferred (Deferred): this will fire with the return of the
|
deferred (Deferred): this will fire with the return of the
|
||||||
|
|
@ -505,7 +510,7 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
_msg_err(caller, _ERROR_UNTRAPPED)
|
_msg_err(caller, _ERROR_UNTRAPPED)
|
||||||
raise ErrorReported
|
raise ErrorReported(raw_string)
|
||||||
finally:
|
finally:
|
||||||
_COMMAND_NESTING[called_by] -= 1
|
_COMMAND_NESTING[called_by] -= 1
|
||||||
|
|
||||||
|
|
@ -536,7 +541,7 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
||||||
try: # catch special-type commands
|
try: # catch special-type commands
|
||||||
|
|
||||||
cmdset = yield get_and_merge_cmdsets(caller, session, player, obj,
|
cmdset = yield get_and_merge_cmdsets(caller, session, player, obj,
|
||||||
callertype)
|
callertype, raw_string)
|
||||||
if not cmdset:
|
if not cmdset:
|
||||||
# this is bad and shouldn't happen.
|
# this is bad and shouldn't happen.
|
||||||
raise NoCmdSets
|
raise NoCmdSets
|
||||||
|
|
@ -603,13 +608,13 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
||||||
raise ExecSystemCommand(cmd, sysarg)
|
raise ExecSystemCommand(cmd, sysarg)
|
||||||
|
|
||||||
# A normal command.
|
# A normal command.
|
||||||
ret = yield _run_command(cmd, cmdname, args)
|
ret = yield _run_command(cmd, cmdname, args, raw_string)
|
||||||
returnValue(ret)
|
returnValue(ret)
|
||||||
|
|
||||||
except ErrorReported:
|
except ErrorReported as exc:
|
||||||
# this error was already reported, so we
|
# this error was already reported, so we
|
||||||
# catch it here and don't pass it on.
|
# catch it here and don't pass it on.
|
||||||
pass
|
logger.log_err("User input was: '%s'." % exc.raw_string)
|
||||||
|
|
||||||
except ExecSystemCommand as exc:
|
except ExecSystemCommand as exc:
|
||||||
# Not a normal command: run a system command, if available,
|
# Not a normal command: run a system command, if available,
|
||||||
|
|
@ -618,7 +623,7 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess
|
||||||
sysarg = exc.sysarg
|
sysarg = exc.sysarg
|
||||||
|
|
||||||
if syscmd:
|
if syscmd:
|
||||||
ret = yield _run_command(syscmd, syscmd.key, sysarg)
|
ret = yield _run_command(syscmd, syscmd.key, sysarg, raw_string)
|
||||||
returnValue(ret)
|
returnValue(ret)
|
||||||
elif sysarg:
|
elif sysarg:
|
||||||
# return system arg
|
# return system arg
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue