Include original exception in ClassNotFound exception

By doing this, we allow the error messages to be more useful. When an import
of a class fails because of a missing module dependency, it would have fail
that way for example:
$ nova-manage
Traceback (most recent call last):
 File "./bin/nova-manage", line 84, in <module>
 from nova import image
 File "/home/jd/Work/src/nova/nova/image/__init__.py", line 22, in <module>
 from nova.image import glance
 File "/home/jd/Work/src/nova/nova/image/glance.py", line 42, in <module>
 GlanceClient = utils.import_class('glance.client.Client')
 File "/home/jd/Work/src/nova/nova/utils.py", line 66, in import_class
 raise exception.ClassNotFound(class_name=class_str)
nova.exception.ClassNotFound: Class Client could not be found
This does not help the user, since it indicates the class Client cannot be
found, even if it is actually found but fail to import.
With this commit, the error message is better:
nova-manage
Traceback (most recent call last):
 File "./bin/nova-manage", line 84, in <module>
 from nova import image
 File "/home/jd/Work/src/nova/nova/image/__init__.py", line 22, in <module>
 from nova.image import glance
 File "/home/jd/Work/src/nova/nova/image/glance.py", line 42, in <module>
 GlanceClient = utils.import_class('glance.client.Client')
 File "/home/jd/Work/src/nova/nova/utils.py", line 66, in import_class
 raise exception.ClassNotFound(class_name=class_str, exception=exc)
nova.exception.ClassNotFound: Class Client could not be found: No module named kombu.connection
This helps to know that in this kombu is missing.
It would probably even better to rename ClassNotFound to
ClassCannotBeImported or something like that too.
Change-Id: I4100d931a0a825fa0729d5467d2f9268fdd2a261
Signed-off-by: Julien Danjou <julien.danjou@enovance.com>
This commit is contained in:
Julien Danjou
2011年10月06日 17:15:32 +02:00
parent c60291ff2b
commit 33e58925c7

View File

@@ -65,6 +65,7 @@ Josh Durgin <joshd@hq.newdream.net>
Josh Kearney <josh@jk0.org>
Josh Kleinpeter <josh@kleinpeter.org>
Joshua McKenty <jmckenty@gmail.com>
Julien Danjou <julien.danjou@enovance.com>
Justin Santa Barbara <justin@fathomdb.com>
Justin Shepherd <jshepher@rackspace.com>
Kei Masumoto <masumotok@nttdata.co.jp>

View File

@@ -735,7 +735,7 @@ class NetworkAdapterNotFound(NotFound):
class ClassNotFound(NotFound):
message = _("Class %(class_name)s could not be found")
message = _("Class %(class_name)s could not be found: %(exception)s")
class NotAllowed(NovaException):

View File

@@ -63,7 +63,7 @@ def import_class(import_str):
return getattr(sys.modules[mod_str], class_str)
except (ImportError, ValueError, AttributeError), exc:
LOG.debug(_('Inner Exception: %s'), exc)
raise exception.ClassNotFound(class_name=class_str)
raise exception.ClassNotFound(class_name=class_str, exception=exc)
def import_object(import_str):
Reference in New Issue
openstack/nova
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.