use exception str() not .message

This mostly fixes the accesses to .message, there is still the
translation that is using the .message.

Partial-bug: #1243883
Change-Id: I709f65e39c017d70eaca5d8f6d06e0227b67e816
This commit is contained in:
Angus Salkeld
2013-10-24 18:08:37 -10:00
parent cda730b4d4
commit a7ac74bb0d
4 changed files with 19 additions and 18 deletions
+4 -4
View File
@@ -278,11 +278,11 @@ def map_remote_error(ex):
ex_type = ex_type[:-len(rpc_common._REMOTE_POSTFIX)]
if ex_type in inval_param_errors:
return HeatInvalidParameterValueError(detail=str(ex.message))
return HeatInvalidParameterValueError(detail=str(ex))
elif ex_type in denied_errors:
return HeatAccessDeniedError(detail=str(ex.message))
return HeatAccessDeniedError(detail=str(ex))
elif ex_type in already_exists_errors:
return AlreadyExistsError(detail=str(ex.message))
return AlreadyExistsError(detail=str(ex))
else:
# Map everything else to internal server error for now
return HeatInternalFailureError(detail=str(ex.message))
return HeatInternalFailureError(detail=str(ex))
+7 -6
View File
@@ -95,14 +95,15 @@ class FaultWrapper(wsgi.Middleware):
if ex_type.endswith(rpc_common._REMOTE_POSTFIX):
ex_type = ex_type[:-len(rpc_common._REMOTE_POSTFIX)]
message = unicode(ex.message)
full_message = unicode(ex)
if full_message.find('\n') > -1:
message, msg_trace = full_message.split('\n', 1)
else:
msg_trace = traceback.format_exc()
message = full_message
if cfg.CONF.debug and not trace:
trace = unicode(ex)
if trace.find('\n') > -1:
unused, trace = trace.split('\n', 1)
else:
trace = traceback.format_exc()
trace = msg_trace
if not webob_exc:
webob_exc = self.error_map.get(ex_type,
+3 -3
View File
@@ -680,7 +680,7 @@ class Resource(object):
http_exc = translate_exception(err, request.best_match_language())
raise exception.HTTPExceptionDisguise(http_exc)
except exception.HeatException as err:
log_exception(err.message, sys.exc_info())
log_exception(err, sys.exc_info())
raise translate_exception(err, request.best_match_language())
except Exception as err:
log_exception(err, sys.exc_info())
@@ -756,7 +756,7 @@ def log_exception(err, exc_info):
def translate_exception(exc, locale):
"""Translates all translatable elements of the given exception."""
exc.message = gettextutils.get_localized_message(exc.message, locale)
exc.message = gettextutils.get_localized_message(str(exc), locale)
if isinstance(exc, webob.exc.HTTPError):
# If the explanation is not a Message, that means that the
# explanation is the default, generic and not translatable explanation
@@ -765,7 +765,7 @@ def translate_exception(exc, locale):
# message, since message is what gets passed in at construction time
# in the API
if not isinstance(exc.explanation, gettextutils.Message):
exc.explanation = exc.message
exc.explanation = str(exc)
exc.detail = ''
else:
exc.explanation = \
+5 -5
View File
@@ -426,14 +426,14 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
ctx_no_pwd, stack_name,
template, params, None, {})
self.assertEqual(
'Missing required credential: X-Auth-Key', ex.message)
'Missing required credential: X-Auth-Key', str(ex))
ex = self.assertRaises(exception.MissingCredentialError,
self.man.create_stack,
ctx_no_user, stack_name,
template, params, None, {})
self.assertEqual(
'Missing required credential: X-Auth-User', ex.message)
'Missing required credential: X-Auth-User', str(ex))
def test_stack_create_total_resources_equals_max(self):
stack_name = 'service_create_stack_total_resources_equals_max'
@@ -743,7 +743,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
template, params, None, {})
self.assertEqual(
'Missing required credential: X-Auth-Key', ex.message)
'Missing required credential: X-Auth-Key', str(ex))
self.m.VerifyAll()
@@ -777,7 +777,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.man._validate_deferred_auth_context,
ctx, stack)
self.assertEqual(
'Missing required credential: X-Auth-User', ex.message)
'Missing required credential: X-Auth-User', str(ex))
# missing password
ctx = utils.dummy_context(password=None)
@@ -785,7 +785,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.man._validate_deferred_auth_context,
ctx, stack)
self.assertEqual(
'Missing required credential: X-Auth-Key', ex.message)
'Missing required credential: X-Auth-Key', str(ex))
class StackServiceUpdateNotSupportedTest(HeatTestCase):