diff options
| author | Matt Riedemann <mriedem@us.ibm.com> | 2015-08-04 14:20:53 -0700 |
|---|---|---|
| committer | Matt Riedemann <mriedem@us.ibm.com> | 2015-08-04 14:21:52 -0700 |
| commit | 03542ee65a5e818a5d908a85a6a9eba21ef63b53 (patch) | |
| tree | e921f2a04516bfd934fe695824bc0ee5c04a773c /cinderclient/exceptions.py | |
| parent | 59fef40f0e9f7754c7a8e9c3b98a3027a46d767d (diff) | |
| download | python-cinderclient-03542ee65a5e818a5d908a85a6a9eba21ef63b53.tar.gz | |
Fix ClientException init when there is no message on py34
BaseException.message was removed in python 3 per PEP 0352 so if no
message is passed to the ClientException __init__ it will blow up:
AttributeError: type object 'ClientException' has no attribute 'message'
So this change does two things:
1. Default to 'n/a' for message and details when body['keys'] doesn't
have a message or details in it (which should be fine since
from_response defaults to n/a if 'keys' is not in body).
2. Use getattr for self.__class__.message and default to None if that
attribute is not set. Arguably we could just remove this and make
the message kwarg default to 'n/a' in ClientException.__init__ but
I figured that was more invasive.
Closes-Bug: #1481478
Change-Id: I738cb9c8d4f015048c45a1df16bf18e29190e392
Diffstat (limited to 'cinderclient/exceptions.py')
| -rw-r--r-- | cinderclient/exceptions.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cinderclient/exceptions.py b/cinderclient/exceptions.py index 4987f24..3c79cee 100644 --- a/cinderclient/exceptions.py +++ b/cinderclient/exceptions.py @@ -82,7 +82,9 @@ class ClientException(Exception): """ def __init__(self, code, message=None, details=None, request_id=None): self.code = code - self.message = message or self.__class__.message + # NOTE(mriedem): Use getattr on self.__class__.message since + # BaseException.message was dropped in python 3, see PEP 0352. + self.message = message or getattr(self.__class__, 'message', None) self.details = details self.request_id = request_id @@ -176,8 +178,8 @@ def from_response(response, body): details = "n/a" if hasattr(body, 'keys'): error = body[list(body)[0]] - message = error.get('message', None) - details = error.get('details', None) + message = error.get('message', message) + details = error.get('details', details) return cls(code=response.status_code, message=message, details=details, request_id=request_id) else: |
