I am debugging an extension that's running in hgweb under mod_wsgi. It had
a bug that was raising an exception on every request, but the only
information I could get out of hgweb was "Internal Server Error".
Everything -- even static files -- simply returned the expansion of
templates/paper/error.tmpl.
The problem with hgweb is that there was no stack trace available for me to
debug my extension.
Here is a rough patch that helps:
"""
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -125,6 +125,7 @@
return False
def run_wsgi(self, req):
+ import sys, traceback
try:
try:
self.refresh()
@@ -159,9 +160,11 @@
repo = hg.repository(self.ui, real)
return hgweb(repo).run_wsgi(req)
except IOError, inst:
+ traceback.print_exc(file=sys.stderr)
msg = inst.strerror
raise ErrorResponse(HTTP_SERVER_ERROR, msg)
except error.RepoError, inst:
+ traceback.print_exc(file=sys.stderr)
raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
# browse subdirectories
@@ -180,6 +183,8 @@
return tmpl("notfound", repo=virtual)
except ErrorResponse, err:
+ #sys.stderr.write('hgwebdir: caught ErrorResponse %r\n' % err)
+ traceback.print_exc(file=sys.stderr)
req.respond(err, ctype)
return tmpl('error', error=err.message or '')
finally:
"""
Problems with that patch:
* hgweb_mod.py needs similar treatment
* multiple stack traces for each exception
...but it's a start. At the very least, it let me find the problem with my
extension! |