diff --git a/django/utils/log.py b/django/utils/log.py index 1f6dc52849..784035b3cf 100644 --- a/django/utils/log.py +++ b/django/utils/log.py @@ -83,7 +83,7 @@ class AdminEmailHandler(logging.Handler): exc_info = record.exc_info stack_trace = '\n'.join(traceback.format_exception(*record.exc_info)) else: - exc_info = () + exc_info = (None, record.msg, None) stack_trace = 'No stack trace available' message = "%s\n\n%s" % (stack_trace, request_repr) diff --git a/django/views/debug.py b/django/views/debug.py index 6bb6a0bd93..569cec18df 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -59,7 +59,7 @@ def technical_500_response(request, exc_type, exc_value, tb): html = reporter.get_traceback_html() return HttpResponseServerError(html, mimetype='text/html') -class ExceptionReporter: +class ExceptionReporter(object): """ A class to organize and coordinate reporting on exceptions. """ @@ -82,7 +82,7 @@ class ExceptionReporter: def get_traceback_html(self): "Return HTML code for traceback." - if issubclass(self.exc_type, TemplateDoesNotExist): + if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist): from django.template.loader import template_source_loaders self.template_does_not_exist = True self.loader_debug_info = [] @@ -113,11 +113,12 @@ class ExceptionReporter: frames = self.get_traceback_frames() for i, frame in enumerate(frames): - frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']] + if 'vars' in frame: + frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']] frames[i] = frame unicode_hint = '' - if issubclass(self.exc_type, UnicodeError): + if self.exc_type and issubclass(self.exc_type, UnicodeError): start = getattr(self.exc_value, 'start', None) end = getattr(self.exc_value, 'end', None) if start is not None and end is not None: @@ -127,11 +128,8 @@ class ExceptionReporter: t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template') c = Context({ 'is_email': self.is_email, - 'exception_type': self.exc_type.__name__, - 'exception_value': smart_unicode(self.exc_value, errors='replace'), 'unicode_hint': unicode_hint, 'frames': frames, - 'lastframe': frames[-1], 'request': self.request, 'settings': get_safe_settings(), 'sys_executable': sys.executable, @@ -143,6 +141,13 @@ class ExceptionReporter: 'template_does_not_exist': self.template_does_not_exist, 'loader_debug_info': self.loader_debug_info, }) + # Check whether exception info is available + if self.exc_type: + c['exception_type'] = self.exc_type.__name__ + if self.exc_value: + c['exception_value'] = smart_unicode(self.exc_value, errors='replace') + if frames: + c['lastframe'] = frames[-1] return t.render(c) def get_template_exception_info(self): @@ -250,14 +255,6 @@ class ExceptionReporter: }) tb = tb.tb_next - if not frames: - frames = [{ - 'filename': '<unknown>', - 'function': '?', - 'lineno': '?', - 'context_line': '???', - }] - return frames def format_exception(self): @@ -319,7 +316,7 @@ TECHNICAL_500_TEMPLATE = """
-