Browse Source

HUE-5120 [core] Popup Exception should log the original stack trace

Instead of empty:

[20/Oct/2016 12:01:47 +0200] cluster      INFO     Resource Manager not available, trying another RM: YARN RM returned a failed response: HTTPConnectionPool(host='quickstart.cloudera', port=8088): Max retries exceeded with url: /ws/v1/cluster/apps?limit=1000&user=hue&finalStatus=UNDEFINED (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x110519050>: Failed to establish a new connection: [Errno 61] Connection refused',)).

[20/Oct/2016 12:01:47 +0200] middleware   INFO     Processing exception: 'SimpleLazyObject' object is not callable: Traceback (most recent call last):
  File "/Users/enrico/Development/Cloudera/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/enrico/Development/Cloudera/hue/build/env/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/transaction.py", line 371, in inner
    return func(*args, **kwargs)
  File "/Users/enrico/Development/Cloudera/hue/apps/jobbrowser/src/jobbrowser/views.py", line 143, in jobs
    raise PopupException(ex)
PopupException: 'SimpleLazyObject' object is not callable

We now get:

[20/Oct/2016 03:20:18 -0700] middleware   INFO     Processing exception: integer division or modulo by zero: Traceback (most recent call last):
  File "/home/romain/projects/hue/build/env/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/romain/projects/hue/build/env/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/transaction.py", line 371, in inner
    return func(*args, **kwargs)
  File "/home/romain/projects/hue/apps/jobbrowser/src/jobbrowser/views.py", line 143, in jobs
    raise PopupException(ex)
PopupException: integer division or modulo by zero
[20/Oct/2016 03:20:18 -0700] exceptions_renderable ERROR    Potential trace: [('/home/romain/projects/hue/apps/jobbrowser/src/jobbrowser/views.py', 135, 'jobs', 'jobs = get_api(request.user, request.jt).get_jobs(user=request.user, username=user, state=state, text=text, retired=retired, limit=1000)'), ('/home/romain/projects/hue/apps/jobbrowser/src/jobbrowser/api.py', 48, 'get_api', 'return YarnApi(user)'), ('/home/romain/projects/hue/apps/jobbrowser/src/jobbrowser/api.py', 183, '__init__', '1/0')]
[20/Oct/2016 03:20:18 -0700] access       INFO     127.0.0.1 romain - "POST /jobbrowser/jobs/ HTTP/1.1"

Which give the exact location of the root exception.

Note: we could prettify the trace more, but unsure if we always get this format of tuples.
Romain Rigaux 9 năm trước cách đây
mục cha
commit
05f914d
1 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 6 1
      desktop/core/src/desktop/lib/exceptions_renderable.py

+ 6 - 1
desktop/core/src/desktop/lib/exceptions_renderable.py

@@ -19,15 +19,18 @@ These methods should never be placed in 'desktop.lib.exceptions'.
 This file exists to remove circular reference caused by importing django_util.
 """
 
+import logging
 import sys
 import traceback
 
 from django.utils.encoding import force_unicode
 
-# Need full import statement
 import desktop.lib.django_util
 
 
+LOG = logging.getLogger(__name__)
+
+
 class PopupException(Exception):
   """
   Middleware will render this exception; and the template
@@ -43,6 +46,8 @@ class PopupException(Exception):
     # 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)
+    if self.traceback:
+      LOG.error('Potential trace: %s' % self.traceback)
 
   def response(self, request):
     data = dict(title=force_unicode(self.title), message=force_unicode(self.message), detail=force_unicode(self.detail) if self.detail else None, traceback=self.traceback)