From d63bd8d692a9eb16caa818101cdbb3358f6b4681 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 14 Mar 2013 13:47:42 -0700 Subject: Don't include traceback when wrapping exceptions The fix in fa52cb09b2270876c9d9a03106f961be6c9db834 strips tracebacks from exceptions when returning them to the user, but it still spams the log with a long traceback. We shouldn't be including the traceback when we wrap the exception in the first place. Instead we just include the message. It also updates the error code to 409 for device in use since this is actually a conflict. Fix for: bug 1155315 bug 1103324 bug 1092610 Change-Id: I95019a3022eb52e0335c455009c13fe229475d03 --- nova/api/openstack/wsgi.py | 13 +++++-------- nova/exception.py | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 5b9900f72..9c8777558 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -656,11 +656,12 @@ class ResourceExceptionHandler(object): return True if isinstance(ex_value, exception.NotAuthorized): - msg = unicode(ex_value) + msg = unicode(ex_value.message % ex_value.kwargs) raise Fault(webob.exc.HTTPForbidden(explanation=msg)) elif isinstance(ex_value, exception.Invalid): + msg = unicode(ex_value.message % ex_value.kwargs) raise Fault(exception.ConvertedException( - code=ex_value.code, explanation=unicode(ex_value))) + code=ex_value.code, explanation=msg)) # Under python 2.6, TypeError's exception value is actually a string, # so test # here via ex_type instead: @@ -1172,12 +1173,8 @@ class Fault(webob.exc.HTTPException): code = self.wrapped_exc.status_int fault_name = self._fault_names.get(code, "computeFault") explanation = self.wrapped_exc.explanation - offset = explanation.find("Traceback") - if offset is not -1: - LOG.debug(_("API request failed, fault raised to the top of" - " the stack. Detailed stacktrace %s") % - explanation) - explanation = explanation[0:offset - 1] + LOG.debug(_("Returning %(code)s to user: %(explanation)s"), + {'code': code, 'explanation': explanation}) fault_data = { fault_name: { diff --git a/nova/exception.py b/nova/exception.py index 046df24c9..3db724fa9 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -388,6 +388,7 @@ class InvalidDevicePath(Invalid): class DevicePathInUse(Invalid): message = _("The supplied device path (%(path)s) is in use.") + code = 409 class DeviceIsBusy(Invalid): -- cgit