diff options
| author | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2011-09-28 15:01:27 +0000 |
|---|---|---|
| committer | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2011-09-28 15:14:56 +0000 |
| commit | 82bef282c93a574ee5cfb2b34e0d8c077c2a7efe (patch) | |
| tree | 2115d58d624441f23b8da35c83338368ee69db59 | |
| parent | a2646129bc9dbd9dec57bdde7f510e0ea7bbddea (diff) | |
| download | nova-82bef282c93a574ee5cfb2b34e0d8c077c2a7efe.tar.gz nova-82bef282c93a574ee5cfb2b34e0d8c077c2a7efe.tar.xz nova-82bef282c93a574ee5cfb2b34e0d8c077c2a7efe.zip | |
Accept message as sole argument to NovaException
Fixes bug 860666
Python nose will sometimes recreate an exception to add captured log
information to the string representation of the exception. It assumes
that it can do this by reinstantiating the class of the originally
triggered exception with one argument, a new string description.
NovaException, and some child classes, didn't work well with this
scheme and would result in a further exception during formatting, which
would result in an unformatted string being displayed.
Change-Id: I7152cb7809fa1deb3986c127370f670fb2da342d
| -rw-r--r-- | nova/exception.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/nova/exception.py b/nova/exception.py index f587173e1..775d9b61f 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -138,17 +138,17 @@ class NovaException(Exception): """ message = _("An unknown exception occurred.") - def __init__(self, **kwargs): + def __init__(self, message=None, **kwargs): self.kwargs = kwargs - try: - self._error_string = self.message % kwargs + if not message: + try: + message = self.message % kwargs - except Exception: - # at least get the core message out if something happened - self._error_string = self.message + except Exception as e: + # at least get the core message out if something happened + message = self.message - def __str__(self): - return self._error_string + super(NovaException, self).__init__(message) class ImagePaginationFailed(NovaException): @@ -168,7 +168,7 @@ class NotAuthorized(NovaException): message = _("Not authorized.") def __init__(self, *args, **kwargs): - super(NotAuthorized, self).__init__(**kwargs) + super(NotAuthorized, self).__init__(*args, **kwargs) class AdminRequired(NotAuthorized): @@ -317,7 +317,7 @@ class NotFound(NovaException): message = _("Resource could not be found.") def __init__(self, *args, **kwargs): - super(NotFound, self).__init__(**kwargs) + super(NotFound, self).__init__(*args, **kwargs) class FlagNotSet(NotFound): |
