Make Exception.format_message aware of Messages

Many API extensions are casting NovaExceptions
directly to unicode with format_message(),
which results in a loss of localization information
from the possibly wrapped Message objects.

This change lets Messages be returned from
NovaException.format_message() if possible, which
will then be translated and resolved to unicode
later when needed.

fixes bug 1229410

Change-Id: I818a35b1d7d910c4f058d870e69c5ff73e45c6bb
This commit is contained in:
Matt Odden
2013-09-23 12:27:04 +00:00
committed by Gerrit Code Review
parent 6b38d96945
commit fc394ac9d8

View File

@@ -136,10 +136,9 @@ 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)
# NOTE(mrodden): use the first argument to the python Exception object
# which should be our full NovaException message, (see __init__)
return self.args[0]
class EncryptionFailure(NovaException):