From 51a6d81d72114adc3987d33451c5422eb27bf59a Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Tue, 11 Apr 2006 03:29:01 +0000 Subject: [PATCH] Fixed #1551 -- Improved base handler to not lose track of important exception in case of exceptions within repr(). Thanks, Ned git-svn-id: http://code.djangoproject.com/svn/django/trunk@2667 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/handlers/base.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 23f04ecd9d..3ed1a33325 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -1,4 +1,5 @@ from django.utils import httpwrappers +import sys class BaseHandler: def __init__(self): @@ -108,12 +109,14 @@ class BaseHandler: if DEBUG: return self.get_technical_error_response(request) else: + # Get the exception info now, in case another exception is thrown later. + exc_info = sys.exc_info() subject = 'Coding error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in INTERNAL_IPS and 'internal' or 'EXTERNAL'), getattr(request, 'path', '')) try: request_repr = repr(request) except: request_repr = "Request repr() unavailable" - message = "%s\n\n%s" % (self._get_traceback(), request_repr) + message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) mail_admins(subject, message, fail_silently=True) return self.get_friendly_error_response(request, resolver) @@ -138,7 +141,7 @@ class BaseHandler: else: return debug.technical_500_response(request, *sys.exc_info()) - def _get_traceback(self): + def _get_traceback(self, exc_info=None): "Helper function to return the traceback as a string" - import sys, traceback - return '\n'.join(traceback.format_exception(*sys.exc_info())) + import traceback + return '\n'.join(traceback.format_exception(*(exc_info or sys.exc_info())))