Made error reporting from cmdsets a little more verbose.
This commit is contained in:
parent
9dcb97060d
commit
7f63ca6a76
1 changed files with 26 additions and 10 deletions
|
|
@ -63,6 +63,8 @@ can then implement separate sets for different situations. For
|
||||||
example, you can have a 'On a boat' set, onto which you then tack on
|
example, you can have a 'On a boat' set, onto which you then tack on
|
||||||
the 'Fishing' set. Fishing from a boat? No problem!
|
the 'Fishing' set. Fishing from a boat? No problem!
|
||||||
"""
|
"""
|
||||||
|
import traceback
|
||||||
|
from imp import find_module
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from evennia.utils import logger, utils
|
from evennia.utils import logger, utils
|
||||||
from evennia.commands.cmdset import CmdSet
|
from evennia.commands.cmdset import CmdSet
|
||||||
|
|
@ -110,11 +112,24 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
is returned for the benefit of the handler.
|
is returned for the benefit of the handler.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
python_paths = [path] + ["%s.%s" % (prefix, path)
|
python_paths = [path] + ["%s.%s" % (prefix, path)
|
||||||
for prefix in _CMDSET_PATHS if not path.startswith(prefix)]
|
for prefix in _CMDSET_PATHS if not path.startswith(prefix)]
|
||||||
errstring = ""
|
errstring = ""
|
||||||
for python_path in python_paths:
|
for python_path in python_paths:
|
||||||
|
|
||||||
|
# check if module exists at all
|
||||||
|
modulepath, classname = python_path.rsplit('.', 1)
|
||||||
|
if python_path.count('.') < 2:
|
||||||
|
extrapath, modulename = "", modulepath
|
||||||
|
else:
|
||||||
|
extrapath, modulename = modulepath.rsplit('.', 1)
|
||||||
|
try:
|
||||||
|
find_module(modulename, [extrapath])
|
||||||
|
except ImportError:
|
||||||
|
# module not found, try next
|
||||||
|
errstring += _("\n(Unsuccessfully tried '%s.' + '%s.%s')." % (extrapath, modulename, classname))
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#print "importing %s: _CACHED_CMDSETS=%s" % (python_path, _CACHED_CMDSETS)
|
#print "importing %s: _CACHED_CMDSETS=%s" % (python_path, _CACHED_CMDSETS)
|
||||||
wanted_cache_key = python_path
|
wanted_cache_key = python_path
|
||||||
|
|
@ -122,7 +137,7 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
if not cmdsetclass:
|
if not cmdsetclass:
|
||||||
#print "cmdset '%s' not in cache. Reloading %s on %s." % (wanted_cache_key, python_path, cmdsetobj)
|
#print "cmdset '%s' not in cache. Reloading %s on %s." % (wanted_cache_key, python_path, cmdsetobj)
|
||||||
# Not in cache. Reload from disk.
|
# Not in cache. Reload from disk.
|
||||||
modulepath, classname = python_path.rsplit('.', 1)
|
#modulepath, classname = python_path.rsplit('.', 1)
|
||||||
module = __import__(modulepath, fromlist=[True])
|
module = __import__(modulepath, fromlist=[True])
|
||||||
cmdsetclass = module.__dict__[classname]
|
cmdsetclass = module.__dict__[classname]
|
||||||
_CACHED_CMDSETS[wanted_cache_key] = cmdsetclass
|
_CACHED_CMDSETS[wanted_cache_key] = cmdsetclass
|
||||||
|
|
@ -132,24 +147,25 @@ def import_cmdset(path, cmdsetobj, emit_to_obj=None, no_logging=False):
|
||||||
errstring = ""
|
errstring = ""
|
||||||
return cmdsetclass
|
return cmdsetclass
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
#logger.log_trace()
|
logger.log_trace()
|
||||||
errstring += _("Error loading cmdset {path}: {error}")
|
errstring += _("\nError loading cmdset {path}: \"{error}\"")
|
||||||
errstring = errstring.format(path=python_path, error=e)
|
errstring = errstring.format(path=python_path, error=e)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
#logger.log_trace()
|
logger.log_trace()
|
||||||
errstring += _("Error in loading cmdset: No cmdset class '{classname}' in {path}.")
|
errstring += _("\nError in loading cmdset: No cmdset class '{classname}' in {path}.")
|
||||||
errstring = errstring.format(classname=classname, path=python_path)
|
errstring = errstring.format(classname=classname, path=python_path)
|
||||||
except SyntaxError, e:
|
except SyntaxError, e:
|
||||||
#logger.log_trace()
|
logger.log_trace()
|
||||||
errstring += _("SyntaxError encountered when loading cmdset '{path}': {error}.")
|
errstring += _("\nSyntaxError encountered when loading cmdset '{path}': \"{error}\".")
|
||||||
errstring = errstring.format(path=python_path, error=e)
|
errstring = errstring.format(path=python_path, error=e)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
#logger.log_trace()
|
logger.log_trace()
|
||||||
errstring += _("Compile/Run error when loading cmdset '{path}': {error}.")
|
errstring += _("\nCompile/Run error when loading cmdset '{path}': \"{error}\".")
|
||||||
errstring = errstring.format(path=python_path, error=e)
|
errstring = errstring.format(path=python_path, error=e)
|
||||||
|
|
||||||
if errstring:
|
if errstring:
|
||||||
# returning an empty error cmdset
|
# returning an empty error cmdset
|
||||||
|
errstring = errstring.strip()
|
||||||
if not no_logging:
|
if not no_logging:
|
||||||
logger.log_errmsg(errstring)
|
logger.log_errmsg(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"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue