Ticket #14972: django-14972-exceptionreporter.patch

File django-14972-exceptionreporter.patch, 5.6 KB (added by Bas Peschier, 14 years ago)
  • django/views/debug.py

     
    8282    def get_traceback_html(self):
    8383        "Return HTML code for traceback."
    8484
    85         if issubclass(self.exc_type, TemplateDoesNotExist):
     85        if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist):
    8686            from django.template.loader import template_source_loaders
    8787            self.template_does_not_exist = True
    8888            self.loader_debug_info = []
     
    111111
    112112        frames = self.get_traceback_frames()
    113113        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']]
    115116            frames[i] = frame
    116117
    117118        unicode_hint = ''
    118         if issubclass(self.exc_type, UnicodeError):
     119        if self.exc_type and issubclass(self.exc_type, UnicodeError):
    119120            start = getattr(self.exc_value, 'start', None)
    120121            end = getattr(self.exc_value, 'end', None)
    121122            if start is not None and end is not None:
     
    125126        t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
    126127        c = Context({
    127128            'is_email': self.is_email,
    128             'exception_type': self.exc_type.__name__,
    129             'exception_value': smart_unicode(self.exc_value, errors='replace'),
    130129            'unicode_hint': unicode_hint,
    131130            'frames': frames,
    132             'lastframe': frames[-1],
    133131            'request': self.request,
    134132            'settings': get_safe_settings(),
    135133            'sys_executable': sys.executable,
     
    141139            'template_does_not_exist': self.template_does_not_exist,
    142140            'loader_debug_info': self.loader_debug_info,
    143141        })
     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],
    144149        return t.render(c)
    145150
    146151    def get_template_exception_info(self):
     
    248253                })
    249254            tb = tb.tb_next
    250255
    251         if not frames:
    252             frames = [{
    253                 'filename': '<unknown>',
    254                 'function': '?',
    255                 'lineno': '?',
    256                 'context_line': '???',
    257             }]
    258 
    259256        return frames
    260257
    261258    def format_exception(self):
     
    317314<head>
    318315  <meta http-equiv="content-type" content="text/html; charset=utf-8">
    319316  <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>
    321318  <style type="text/css">
    322319    html * { padding:0; margin:0; }
    323320    body * { padding:10px 20px; }
     
    427424</head>
    428425<body>
    429426<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>
    432429  <table class="meta">
     430{% if request %}
    433431    <tr>
    434432      <th>Request Method:</th>
    435433      <td>{{ request.META.REQUEST_METHOD }}</td>
     
    438436      <th>Request URL:</th>
    439437      <td>{{ request.build_absolute_uri|escape }}</td>
    440438    </tr>
     439{% endif %}
    441440    <tr>
    442441      <th>Django Version:</th>
    443442      <td>{{ django_version_info }}</td>
    444443    </tr>
     444{% if exception_type %}
    445445    <tr>
    446446      <th>Exception Type:</th>
    447447      <td>{{ exception_type }}</td>
    448448    </tr>
     449{% endif %}
     450{% if exception_value %}
    449451    <tr>
    450452      <th>Exception Value:</th>
    451453      <td><pre>{{ exception_value|force_escape }}</pre></td>
    452454    </tr>
     455{% endif %}
     456{% if lastframe %}
    453457    <tr>
    454458      <th>Exception Location:</th>
    455459      <td>{{ lastframe.filename|escape }} in {{ lastframe.function|escape }}, line {{ lastframe.lineno }}</td>
    456460    </tr>
     461{% endif %}
    457462    <tr>
    458463      <th>Python Executable:</th>
    459464      <td>{{ sys_executable|escape }}</td>
     
    513518   </table>
    514519</div>
    515520{% endif %}
     521{% if frames %}
    516522<div id="traceback">
    517523  <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>
    518524  {% autoescape off %}
     
    613619</form>
    614620</div>
    615621{% endif %}
     622{% endif %}
    616623
    617624<div id="requestinfo">
    618625  <h2>Request information</h2>
     
    723730      {% endfor %}
    724731    </tbody>
    725732  </table>
     733{% else %}
     734  <p>Request data not supplied</p>
    726735{% endif %}
    727736
    728737  <h3 id="settings-info">Settings</h3>
  • django/utils/log.py

     
    8383            exc_info = record.exc_info
    8484            stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
    8585        else:
    86             exc_info = ()
     86            exc_info = (None, None, None, )
    8787            stack_trace = 'No stack trace available'
    8888
    8989        message = "%s\n\n%s" % (stack_trace, request_repr)
Back to Top