Skip to content

Commit

Permalink
Added better traceback output to the console. Thanks to tstromberg fo…
Browse files Browse the repository at this point in the history
…r the original patch.
  • Loading branch information
toastdriven committed Dec 5, 2009
1 parent e5b0cc3 commit d695710
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Primary authors:

* Daniel Lindsley


Contributors:

* Matt Croydon for various patches and suggestions
* Christian Metts for various patches and suggestions
* marly for a patch to an exception's message
* tstromberg for a patch related to printing tracebacks on errors
8 changes: 8 additions & 0 deletions examples/detail_on_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from itty import *

@get('/test_500')
def test_500(request):
raise RuntimeError('Oops.')
return 'This should never happen either.'

run_itty()
11 changes: 10 additions & 1 deletion itty.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def index(request):
import mimetypes
import os
import re
import sys
import traceback
import urlparse
try:
from urlparse import parse_qs
Expand Down Expand Up @@ -225,7 +227,14 @@ def handle_request(environ, start_response):

def handle_error(exception, request):
"""If an exception is thrown, deal with it and present an error page."""
request._environ['wsgi.errors'].write("Exception occurred on '%s': %s\n" % (request._environ['PATH_INFO'], exception))
(e_type, e_value, e_tb) = sys.exc_info()
message = "%s occurred on '%s': %s\nTraceback: %s" % (
exception.__class__,
request._environ['PATH_INFO'],
exception,
''.join(traceback.format_exception(e_type, e_value, e_tb))
)
request._environ['wsgi.errors'].write(message)

if isinstance(exception, RequestError):
status = getattr(exception, 'status', 404)
Expand Down

0 comments on commit d695710

Please sign in to comment.