summaryrefslogtreecommitdiffstats
path: root/nova/exception.py
diff options
context:
space:
mode:
authorNikola Dipanov <ndipanov@redhat.com>2013-03-25 17:10:23 +0100
committerNikola Dipanov <ndipanov@redhat.com>2013-03-27 17:18:13 +0100
commitb936df8c1ec47300540403ebb6833f0fbf5f195f (patch)
treeff2870f53cf8af0c462c880f1667845482f050d4 /nova/exception.py
parente9912c6dd1c53a59822cc4332a7de0630f1ca0bb (diff)
downloadnova-b936df8c1ec47300540403ebb6833f0fbf5f195f.tar.gz
nova-b936df8c1ec47300540403ebb6833f0fbf5f195f.tar.xz
nova-b936df8c1ec47300540403ebb6833f0fbf5f195f.zip
Add a format_message method to the Exceptions
This patch adds a format_message method to the NovaException class that will almost always do what a user wants, when they want to print out the message of the exception. Exceptions that are received through RPC are turned into an actual exception classes by the deserialize_remote_exception function of the nova.openstack.common.rpc.common module. This function then overrides __str__ and __unicode__ methods of a new class to print the whole trace. We still want to preserve this functionality (for logging) but do not want to leak the trace back to the user in the HTTP response. Based on the above, This patch attempts to establish a convention that states: if you need to get the message of a NovaException subclass - always use the format_message method. Only use str(e) or unicode(e) when you suspect that they were overriden. Initially this was attempted through adding a custom metaclass to the NovaException class so that format_message cannot be overridden in subclasses, however due to a bug in testtools - many tests were failing. A patch was proposed to testtols to remedy this (https://github.com/testing-cabal/testtools/pull/34) however until it is merged, we cannot use metaclasses with our exception classes as they cause tests to fail. Change-Id: I0a399b9ab3227bad644b031c9b689fe0ce64586e
Diffstat (limited to 'nova/exception.py')
-rw-r--r--nova/exception.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/nova/exception.py b/nova/exception.py
index cfc237120..1f32b0671 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -161,6 +161,12 @@ class NovaException(Exception):
super(NovaException, self).__init__(message)
+ def format_message(self):
+ if self.__class__.__name__.endswith('_Remote'):
+ return self.args[0]
+ else:
+ return unicode(self)
+
class EC2APIError(NovaException):
message = _("Unknown")