Separate message and traceback even if not a remote error

Faultwrap exposes tracebacks in error messages when Oslo.messaging
cannot add a _remote suffix to the exception generated by the Heat
engine.

Change-Id: Iaf91dafacce1abe94fb10aa2ba380cafb6fc4a84
closes-bug: #1432726
This commit is contained in:
Drago Rosson 2015-03-13 17:52:44 +00:00
parent 45be90bb22
commit a2124b8c7e
2 changed files with 21 additions and 1 deletions

View File

@ -104,6 +104,7 @@ class FaultWrapper(wsgi.Middleware):
def _error(self, ex): def _error(self, ex):
trace = None trace = None
traceback_marker = 'Traceback (most recent call last)'
webob_exc = None webob_exc = None
if isinstance(ex, exception.HTTPExceptionDisguise): if isinstance(ex, exception.HTTPExceptionDisguise):
# An HTTP exception was disguised so it could make it here # An HTTP exception was disguised so it could make it here
@ -120,8 +121,12 @@ class FaultWrapper(wsgi.Middleware):
ex_type = ex_type[:-len('_Remote')] ex_type = ex_type[:-len('_Remote')]
full_message = six.text_type(ex) full_message = six.text_type(ex)
if full_message.find('\n') > -1 and is_remote: if '\n' in full_message and is_remote:
message, msg_trace = full_message.split('\n', 1) message, msg_trace = full_message.split('\n', 1)
elif traceback_marker in full_message:
message, msg_trace = full_message.split(traceback_marker, 1)
message = message.rstrip('\n')
msg_trace = traceback_marker + msg_trace
else: else:
msg_trace = traceback.format_exc() msg_trace = traceback.format_exc()
message = full_message message = full_message

View File

@ -53,6 +53,21 @@ class FaultMiddlewareTest(common.HeatTestCase):
'title': 'Bad Request'} 'title': 'Bad Request'}
self.assertEqual(expected, msg) self.assertEqual(expected, msg)
def test_http_exception_with_traceback(self):
wrapper = fault.FaultWrapper(None)
newline_error = ErrorWithNewline(
'Error with \n newline\nTraceback (most recent call last):\nFoo')
msg = wrapper._error(heat_exc.HTTPExceptionDisguise(newline_error))
expected = {'code': 400,
'error': {'message': 'Error with \n newline',
'traceback': None,
'type': 'ErrorWithNewline'},
'explanation': ('The server could not comply with the '
'request since it is either malformed '
'or otherwise incorrect.'),
'title': 'Bad Request'}
self.assertEqual(expected, msg)
def test_openstack_exception_with_kwargs(self): def test_openstack_exception_with_kwargs(self):
wrapper = fault.FaultWrapper(None) wrapper = fault.FaultWrapper(None)
msg = wrapper._error(heat_exc.StackNotFound(stack_name='a')) msg = wrapper._error(heat_exc.StackNotFound(stack_name='a'))