Showing posts with label templates. Show all posts
Showing posts with label templates. Show all posts

Friday, October 21, 2011

IndexError: tuple index out of range in get_template_exception_info

Sometimes people do not specify messages, when they're firing exceptions. In that case, one day we can get something like this in http server stdout:
  File "/Users/pythonaut/.virtualenvs/dev/src/django/django/core/handlers/base.py", line 221, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/pythonaut/.virtualenvs/dev/src/django/django/views/debug.py", line 66, in technical_500_response
    html = reporter.get_traceback_html()
  File "/Users/pythonaut/.virtualenvs/dev/src/django/django/views/debug.py", line 275, in get_traceback_html
    c = Context(self.get_traceback_data())
  File "/Users/pythonaut/.virtualenvs/dev/src/django/django/views/debug.py", line 231, in get_traceback_data
    self.get_template_exception_info()
  File "/Users/pythonaut/.virtualenvs/dev/src/django/django/views/debug.py", line 306, in get_template_exception_info
    'message': self.exc_value.args[0],
IndexError: tuple index out of range
And in a browser
A server error has occurred. Please contact the administrator
Quick workaround
  1. Open /Users/pythonaut/.virtualenvs/dev/src/django/django/views/debug.py(use your own path from error trace) in your favourite editor
  2. Goto line 306, find this text
  3.     'message': self.exc_value.args[0],
    
  4. Replace it with
  5.     'message': self.exc_value.args[0] if self.exc_value.args else None,
    
Now you can restart http server(if it wasn't done automagically) and see detailed debug information.