diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index 9ed4020b63..aaebe95312 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -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) diff --git a/src/commands/cmdsethandler.py b/src/commands/cmdsethandler.py index 9252ac00ef..6f58e3021f 100644 --- a/src/commands/cmdsethandler.py +++ b/src/commands/cmdsethandler.py @@ -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