Django

Code

Ticket #5046: views_debug_unicodeerror_hint.2.diff

File views_debug_unicodeerror_hint.2.diff, 1.1 kB (added by Thomas Güttler <hv@tbz-pariv.de>, 1 year ago)
  • views/debug.py

    old new  
    123128            'function': '?', 
    124129            'lineno': '?', 
    125130        }] 
     131 
     132    hint="" 
     133    if issubclass(exc_type, UnicodeError): 
     134        start=getattr(exc_value, 'start', None) 
     135        end=getattr(exc_value, 'end', None) 
     136        if start!=None and end!=None: 
     137            ustr=exc_value.args[1] 
     138            hint=smart_unicode(ustr[max(start-5, 0):min(end+5, len(ustr))], "ascii", errors="replace") 
    126139    t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template') 
    127140    c = Context({ 
    128141        'exception_type': exc_type.__name__, 
    129142        'exception_value': smart_unicode(exc_value, errors='replace'), 
     143        'hint': hint, 
    130144        'frames': frames, 
    131145        'lastframe': frames[-1], 
    132146        'request': request, 
     
    356370      <th>Python Version:</th> 
    357371      <td>{{ sys_version_info }}</td> 
    358372    </tr> 
     373    <tr> 
     374      <th>Hint:</th> 
     375      <td>{{ hint }}</td> 
     376    </tr> 
    359377  </table> 
    360378</div> 
    361379{% if template_does_not_exist %}