Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 (testing-cabal/testtools#34) however until it is merged, we cannot use metaclasses with our exception classes as they cause tests to fail. Change-Id: I0a399b9ab3227bad644b031c9b689fe0ce64586e
- Loading branch information