Made more verbose message when not finding a typeclass.

This commit is contained in:
Griatch 2015-01-15 21:49:05 +01:00
parent a34312245a
commit 4298dddf29
2 changed files with 13 additions and 9 deletions

View file

@ -278,7 +278,7 @@ SERVER_SESSION_CLASS = "evennia.server.serversession.ServerSession"
# defined relative evennia's root directory. They will be searched in # defined relative evennia's root directory. They will be searched in
# order to find relative typeclass paths. # order to find relative typeclass paths.
OBJECT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"] OBJECT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
SCRIPT_TYPECLASS_PATHS = ["typeclasses" "evennia.contrib", "evennia.contrib.tutorial_examples"] SCRIPT_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
PLAYER_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"] PLAYER_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]
CHANNEL_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"] CHANNEL_TYPECLASS_PATHS = ["typeclasses", "evennia.contrib", "evennia.contrib.tutorial_examples"]

View file

@ -18,7 +18,7 @@ import random
import traceback import traceback
from subprocess import check_output from subprocess import check_output
from importlib import import_module from importlib import import_module
from inspect import ismodule from inspect import ismodule, trace
from collections import defaultdict from collections import defaultdict
from twisted.internet import threads, defer, reactor from twisted.internet import threads, defer, reactor
from django.conf import settings from django.conf import settings
@ -939,23 +939,27 @@ def class_from_module(path, defaultpaths=None):
raise ImportError("the path '%s' is not on the form modulepath.Classname." % path) raise ImportError("the path '%s' is not on the form modulepath.Classname." % path)
try: try:
mod = import_module(testpath, package="evennia") mod = import_module(testpath, package="evennia")
except ImportError, ex: except ImportError:
# normally this is due to a not-found property if len(trace()) > 2:
if not str(ex).startswith("No module named"):# %s" % path): # this means the error happened within the called module and
# we must not hide it.
exc = sys.exc_info() exc = sys.exc_info()
raise exc[1], None, exc[2] raise exc[1], None, exc[2]
continue else:
# otherwise, try the next suggested path
continue
try: try:
cls = getattr(mod, clsname) cls = getattr(mod, clsname)
break break
except AttributeError, ex: except AttributeError:
if not str(ex).startswith("'module' object has no attribute '%s'" % clsname): if len(trace()) > 2:
# AttributeError within the module, don't hide it
exc = sys.exc_info() exc = sys.exc_info()
raise exc[1], None, exc[2] raise exc[1], None, exc[2]
if not cls: if not cls:
err = "Could not load typeclass '%s'" % path err = "Could not load typeclass '%s'" % path
if defaultpaths: if defaultpaths:
err += " (paths searched: %s)" % ", ".join(paths) err += "\nPaths searched:\n %s" % "\n ".join(paths)
else: else:
err += "." err += "."
raise ImportError(err) raise ImportError(err)