#21777: Make request exception handling more robust to subsequent exceptions
--------------------------------------+------------------------------------
     Reporter:  patrakov@…            |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  HTTP handling         |                  Version:  1.6
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Ludwig Kjellström):

 Hi, I pulled a random ticket and landed here.

 This is still not handled very well. (Even though PEP 3134 Exception
 Chaining https://www.python.org/dev/peps/pep-3134/ has led to a good error
 message once it gets printed.).
 With `DEBUG=True` an error in the error handler leads to plain text `A
 server error occurred.  Please contact the administrator.`.

 Current reproducible project is found here, based upon Patrakovs code:
 https://github.com/metteludwig/django-bug-21777/tree/master

 A trivial solution is to wrap the signals-call in try/catch and then
 trivially pass along ''the new'' exception to `handle_uncaught_exception`
 and `log_response`, thus logging the handler exception.


 Current: (django/core/handlers/exception.py:89)
 {{{
 else:
     signals.got_request_exception.send(sender=None, request=request)
     response = handle_uncaught_exception(request,
 get_resolver(get_urlconf()), sys.exc_info())
     log_response(
         '%s: %s', response.reason_phrase, request.path,
         response=response,
         request=request,
         exc_info=sys.exc_info(),
     )
 }}}

 Actually passing along the error for logging and building debug-response:

 {{{

 else:
         try:
             signals.got_request_exception.send(sender=None,
 request=request)
         except Exception as e:
             # A new exception was raised by a receiver of
 got_request_exception
             # If we don't catch it, it will just recurse.
             response = handle_uncaught_exception(request,
 get_resolver(get_urlconf()), sys.exc_info())
             log_response(
                 '%s: %s', response.reason_phrase, request.path,
                 response=response,
                 request=request,
                 exc_info=sys.exc_info(),
             )
         else:
             response = handle_uncaught_exception(request,
 get_resolver(get_urlconf()), sys.exc_info())
             log_response(
                 '%s: %s', response.reason_phrase, request.path,
                 response=response,
                 request=request,
                 exc_info=sys.exc_info(),
             )
 }}}


 Does any one have any pointers on how to improve this? This is the most
 trivial solution, just to showcase the solution.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21777#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/076.9ab8b31d114fc4cff9b9834d30e99836%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to