[core] Give previous traceback to PopupException
@@ -31,11 +31,15 @@ import desktop.lib.django_util
LOG = logging.getLogger(__name__)
+def raise_popup_exception(message, title="Error", detail=None, error_code=500):
+ tb = sys.exc_info()
+ raise PopupException(message, title=title, detail=detail, error_code=error_code, traceback=traceback.extract_tb(tb[2]))
+
class PopupException(Exception):
"""
Middleware will render this exception; and the template renders it as a pop-up.
"""
- def __init__(self, message, title="Error", detail=None, error_code=500):
+ def __init__(self, message, title="Error", detail=None, error_code=500, tb=None):
Exception.__init__(self, message)
self.message = message
self.title = title
@@ -45,9 +49,13 @@ class PopupException(Exception):
if self.detail:
LOG.error('Potential detail: %s' % self.detail)
+ if tb:
+ self.traceback = tb
+ else: # At this point the previous trace is already lost
# Traceback is only relevant if an exception was thrown, caught, and we reraise with this exception.
- (type, value, tb) = sys.exc_info()
- self.traceback = traceback.extract_tb(tb)
+ tb = sys.exc_info()
+ self.traceback = traceback.extract_tb(tb[2])
+
if self.traceback:
LOG.error('Potential trace: %s' % self.traceback)
