Ticket #14972: django-14972-exceptionreporter.patch
File django-14972-exceptionreporter.patch, 5.6 KB (added by , 14 years ago) |
---|
-
django/views/debug.py
82 82 def get_traceback_html(self): 83 83 "Return HTML code for traceback." 84 84 85 if issubclass(self.exc_type, TemplateDoesNotExist):85 if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist): 86 86 from django.template.loader import template_source_loaders 87 87 self.template_does_not_exist = True 88 88 self.loader_debug_info = [] … … 111 111 112 112 frames = self.get_traceback_frames() 113 113 for i, frame in enumerate(frames): 114 frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']] 114 if 'vars' in frame: 115 frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']] 115 116 frames[i] = frame 116 117 117 118 unicode_hint = '' 118 if issubclass(self.exc_type, UnicodeError):119 if self.exc_type and issubclass(self.exc_type, UnicodeError): 119 120 start = getattr(self.exc_value, 'start', None) 120 121 end = getattr(self.exc_value, 'end', None) 121 122 if start is not None and end is not None: … … 125 126 t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template') 126 127 c = Context({ 127 128 'is_email': self.is_email, 128 'exception_type': self.exc_type.__name__,129 'exception_value': smart_unicode(self.exc_value, errors='replace'),130 129 'unicode_hint': unicode_hint, 131 130 'frames': frames, 132 'lastframe': frames[-1],133 131 'request': self.request, 134 132 'settings': get_safe_settings(), 135 133 'sys_executable': sys.executable, … … 141 139 'template_does_not_exist': self.template_does_not_exist, 142 140 'loader_debug_info': self.loader_debug_info, 143 141 }) 142 # Check whether exception info is available 143 if self.exc_type: 144 c['exception_type'] = self.exc_type.__name__ 145 if self.exc_value: 146 c['exception_value'] = smart_unicode(self.exc_value, errors='replace') 147 if frames: 148 c['lastframe'] = frames[-1], 144 149 return t.render(c) 145 150 146 151 def get_template_exception_info(self): … … 248 253 }) 249 254 tb = tb.tb_next 250 255 251 if not frames:252 frames = [{253 'filename': '<unknown>',254 'function': '?',255 'lineno': '?',256 'context_line': '???',257 }]258 259 256 return frames 260 257 261 258 def format_exception(self): … … 317 314 <head> 318 315 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 319 316 <meta name="robots" content="NONE,NOARCHIVE"> 320 <title>{ { exception_type }} at {{ request.path_info|escape }}</title>317 <title>{% if exception_type %}{{ exception_type }}{% else %}Report{% endif %}{% if request %} at {{ request.path_info|escape }}{% endif %}</title> 321 318 <style type="text/css"> 322 319 html * { padding:0; margin:0; } 323 320 body * { padding:10px 20px; } … … 427 424 </head> 428 425 <body> 429 426 <div id="summary"> 430 <h1>{ { exception_type }}{% if request %} at {{ request.path_info|escape }}{% endif %}</h1>431 <pre class="exception_value">{ { exception_value|force_escape }}</pre>427 <h1>{% if exception_type %}{{ exception_type }}{% else %}Report{% endif %}{% if request %} at {{ request.path_info|escape }}{% endif %}</h1> 428 <pre class="exception_value">{% if exception_value %}{{ exception_value|force_escape }}{% else %}No exception supplied{% endif %}</pre> 432 429 <table class="meta"> 430 {% if request %} 433 431 <tr> 434 432 <th>Request Method:</th> 435 433 <td>{{ request.META.REQUEST_METHOD }}</td> … … 438 436 <th>Request URL:</th> 439 437 <td>{{ request.build_absolute_uri|escape }}</td> 440 438 </tr> 439 {% endif %} 441 440 <tr> 442 441 <th>Django Version:</th> 443 442 <td>{{ django_version_info }}</td> 444 443 </tr> 444 {% if exception_type %} 445 445 <tr> 446 446 <th>Exception Type:</th> 447 447 <td>{{ exception_type }}</td> 448 448 </tr> 449 {% endif %} 450 {% if exception_value %} 449 451 <tr> 450 452 <th>Exception Value:</th> 451 453 <td><pre>{{ exception_value|force_escape }}</pre></td> 452 454 </tr> 455 {% endif %} 456 {% if lastframe %} 453 457 <tr> 454 458 <th>Exception Location:</th> 455 459 <td>{{ lastframe.filename|escape }} in {{ lastframe.function|escape }}, line {{ lastframe.lineno }}</td> 456 460 </tr> 461 {% endif %} 457 462 <tr> 458 463 <th>Python Executable:</th> 459 464 <td>{{ sys_executable|escape }}</td> … … 513 518 </table> 514 519 </div> 515 520 {% endif %} 521 {% if frames %} 516 522 <div id="traceback"> 517 523 <h2>Traceback <span class="commands">{% if not is_email %}<a href="#" onclick="return switchPastebinFriendly(this);">Switch to copy-and-paste view</a></span>{% endif %}</h2> 518 524 {% autoescape off %} … … 613 619 </form> 614 620 </div> 615 621 {% endif %} 622 {% endif %} 616 623 617 624 <div id="requestinfo"> 618 625 <h2>Request information</h2> … … 723 730 {% endfor %} 724 731 </tbody> 725 732 </table> 733 {% else %} 734 <p>Request data not supplied</p> 726 735 {% endif %} 727 736 728 737 <h3 id="settings-info">Settings</h3> -
django/utils/log.py
83 83 exc_info = record.exc_info 84 84 stack_trace = '\n'.join(traceback.format_exception(*record.exc_info)) 85 85 else: 86 exc_info = ( )86 exc_info = (None, None, None, ) 87 87 stack_trace = 'No stack trace available' 88 88 89 89 message = "%s\n\n%s" % (stack_trace, request_repr)