Emailing tracebacks in web.py

Traceback screenshotMost web apps have bugs. It’s just the way things are — you usually need to launch before you’re satisfied your latest startup is 100% bug-free, if there is such a thing. One of the nice things about a web app is that it’s easy to let your first users help you find bugs.

Both microPledge and DecentURL use Python and the minimalist web.py framework. It’s easy to set up web.py to show nice error tracebacks to the user (good for development), but it’s not a built-in feature to email real tracebacks to the site admins.

We’ve found emailed tracebacks particularly handy, so I thought I’d share the code. Nothing fancy, but it works well, and has proved invaluable for the live debugging of our own web applications. I’m not terribly familiar with other web frameworks, but I imagine the concept wouldn’t be too hard to port.

A couple of security notes:

Anyway, have a look at the code: emailerror.py. It’s a stand-alone web.py WSGI app that shows you how to do it. Have fun!

20 November 2007 by Ben    4 comments

4 comments (oldest first)

karim 20 Nov 2007, 23:54 link

A thousand thanks Ben! Simple yet very useful! We’ll sure use it in our web.py app too :) In fact, http://xhtml-css.com currently doesn’t provide us yet with much error feedback and your solution comes really in time! Thank you!

Greg 21 Nov 2007, 02:31 link

Excellent work! Utility Mill has got them now. Very useful indeed.

Rudolf Olah 21 Nov 2007, 03:45 link

Great stuff. I have some code lying around for generating bug reports for regular Python apps. Maybe I’ll post it sometime.

Ian Bicking 21 Nov 2007, 11:16 link

Paste (and by extension Pylons) do this as WSGI middleware; the exception catcher wraps your application, and if an exception escapes from your application it is handled by the middleware. It can display it and/or email it to you. It’s also what the interactive debugger is built on.

This stuff has been extracted into a separate project recently: https://www.knowledgetap.com/hg/weberror/ — I don’t know if web.py makes this sort of middleware easy to apply to an application.