Use human readable exception messages

Currently, the exceptions are nothing if converted to strings.
The doc strings are human reable and useful to users, so use them.
Before:

    $ python examples/connection.py
    ERROR: Exception raised:
    $

After:

    $ python examples/connection.py
    ERROR: Exception raised: Could not find requested endpoint in Service Catalog.
    $

Change-Id: I1300e411c93bdfb17975e4f61e925b5b6474434c
This commit is contained in:
TerryHowe 2015-08-13 11:24:33 -06:00
parent 2ab831ce6f
commit c7f60421a0
7 changed files with 22 additions and 20 deletions

View File

@ -14,5 +14,4 @@ from keystoneauth1.exceptions import base
class AuthorizationFailure(base.ClientException): class AuthorizationFailure(base.ClientException):
"""Cannot authorize API client.""" message = "Cannot authorize API client."
pass

View File

@ -14,11 +14,11 @@ from keystoneauth1.exceptions import base
class AuthPluginException(base.ClientException): class AuthPluginException(base.ClientException):
"""Something went wrong with auth plugins.""" message = "Something went wrong with auth plugins."
class MissingAuthPlugin(AuthPluginException): class MissingAuthPlugin(AuthPluginException):
"""An authenticated request is required but no plugin available.""" message = "An authenticated request is required but no plugin available."
class NoMatchingPlugin(AuthPluginException): class NoMatchingPlugin(AuthPluginException):

View File

@ -16,3 +16,12 @@ __all__ = ['ClientException']
class ClientException(Exception): class ClientException(Exception):
"""The base exception for everything to do with clients.""" """The base exception for everything to do with clients."""
message = None
def __init__(self, message=None):
if not message:
if self.message:
message = self.message
else:
message = self.__class__.__name__
super(Exception, self).__init__(message)

View File

@ -19,14 +19,12 @@ __all__ = ['CatalogException',
class CatalogException(base.ClientException): class CatalogException(base.ClientException):
"""Something is rotten in Service Catalog.""" message = "Something is rotten in Service Catalog."
class EndpointNotFound(CatalogException): class EndpointNotFound(CatalogException):
"""Could not find requested endpoint in Service Catalog.""" message = "Could not find requested endpoint in Service Catalog."
pass
class EmptyCatalog(EndpointNotFound): class EmptyCatalog(EndpointNotFound):
"""The service catalog is empty.""" message = "The service catalog is empty."
pass

View File

@ -26,23 +26,19 @@ class RetriableConnectionFailure(Exception):
class ConnectionError(base.ClientException): class ConnectionError(base.ClientException):
"""Cannot connect to API service.""" message = "Cannot connect to API service."
pass
class ConnectTimeout(ConnectionError, RetriableConnectionFailure): class ConnectTimeout(ConnectionError, RetriableConnectionFailure):
"""Timed out connecting to service""" message = "Timed out connecting to service"
pass
class ConnectFailure(ConnectionError, RetriableConnectionFailure): class ConnectFailure(ConnectionError, RetriableConnectionFailure):
"""A retryable connection failure.""" message = "A retryable connection failure."
pass
class SSLError(ConnectionError): class SSLError(ConnectionError):
"""An SSL error occurred.""" message = "An SSL error occurred."
pass
class UnknownConnectionError(ConnectionError): class UnknownConnectionError(ConnectionError):

View File

@ -18,8 +18,8 @@ __all__ = ['DiscoveryFailure',
class DiscoveryFailure(base.ClientException): class DiscoveryFailure(base.ClientException):
"""Discovery of client versions failed.""" message = "Discovery of client versions failed."
class VersionNotAvailable(DiscoveryFailure): class VersionNotAvailable(DiscoveryFailure):
"""Discovery failed as the version you requested is not available.""" message = "Discovery failed as the version you requested is not available."

View File

@ -18,7 +18,7 @@ __all__ = ['InvalidResponse']
class InvalidResponse(base.ClientException): class InvalidResponse(base.ClientException):
"""The response from the server is not valid for this request.""" message = "The response from the server is not valid for this request."
def __init__(self, response): def __init__(self, response):
super(InvalidResponse, self).__init__() super(InvalidResponse, self).__init__()