From c519767a55efebdb488498b689fc3dee2fc5ac42 Mon Sep 17 00:00:00 2001 From: Craig Bryant Date: Tue, 12 Jul 2016 13:18:06 -0600 Subject: [PATCH] Fix __str__ not returning a String for KeystoneException KeystoneExcepion is only created with the Exception returned by Keystone. However, since it was derived from BaseException, __init__ expected a message not an Exception. This caused: TypeError: __str__ returned non-string (type AuthorizationFailure) if you tried to print out the resulting KeystoneException. Fixed this by deriving from Exception which knows how to handle an Exception passed in Change-Id: I6450b59f5ccd32d34ea3e531098eeebfcb36196e --- monascaclient/exc.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/monascaclient/exc.py b/monascaclient/exc.py index 5a2e709..cf4f87c 100644 --- a/monascaclient/exc.py +++ b/monascaclient/exc.py @@ -1,4 +1,4 @@ -# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP +# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -54,19 +54,13 @@ class RequestTimeoutError(BaseException): """Timeout making a POST, GET, PATCH, DELETE, or PUT request to the server.""" -class KeystoneException(BaseException): +class KeystoneException(Exception): """Base exception for all Keystone-derived exceptions.""" - code = 'N/A' - - def __init__(self, message=None): - super(KeystoneException, self).__init__(message) - try: - log.error("exception: {}".format(message)) - self.error = jsonutils.loads(message) - except Exception: - self.error = {'error': - {'message': self.message or self.__class__.__doc__}} + # This is initialized with the exception raised by the Keystone client so + # deriving this class from Exception instead of BaseException allows that to + # be handled without any additional code + pass class HTTPException(BaseException):