Show More
@@ -0,0 +1,17 b'' | |||
|
1 | # A dummy extension that installs an hgweb command that throws an Exception. | |
|
2 | ||
|
3 | from mercurial.hgweb import webcommands | |
|
4 | ||
|
5 | def raiseerror(web, req, tmpl): | |
|
6 | '''Dummy web command that raises an uncaught Exception.''' | |
|
7 | ||
|
8 | # Simulate an error after partial response. | |
|
9 | if 'partialresponse' in req.form: | |
|
10 | req.respond(200, 'text/plain') | |
|
11 | req.write('partial content\n') | |
|
12 | ||
|
13 | raise AttributeError('I am an uncaught error!') | |
|
14 | ||
|
15 | def extsetup(ui): | |
|
16 | setattr(webcommands, 'raiseerror', raiseerror) | |
|
17 | webcommands.__all__.append('raiseerror') |
@@ -81,6 +81,7 b' class _httprequesthandler(BaseHTTPServer' | |||
|
81 | 81 | except Exception: |
|
82 | 82 | self._start_response("500 Internal Server Error", []) |
|
83 | 83 | self._write("Internal Server Error") |
|
84 | self._done() | |
|
84 | 85 | tb = "".join(traceback.format_exception(*sys.exc_info())) |
|
85 | 86 | self.log_error("Exception happened during processing " |
|
86 | 87 | "request '%s':\n%s", self.path, tb) |
@@ -43,9 +43,8 b' def request(host, path, show):' | |||
|
43 | 43 | print "%s: %s" % (h, response.getheader(h)) |
|
44 | 44 | if not headeronly: |
|
45 | 45 | |
|
46 | if response.status != 500: | |
|
47 | data = response.read() | |
|
48 | sys.stdout.write(data) | |
|
46 | data = response.read() | |
|
47 | sys.stdout.write(data) | |
|
49 | 48 | |
|
50 | 49 | if twice and response.getheader('ETag', None): |
|
51 | 50 | tag = response.getheader('ETag') |
@@ -579,4 +579,30 b' errors' | |||
|
579 | 579 | |
|
580 | 580 | $ cat errors.log |
|
581 | 581 | |
|
582 | Uncaught exceptions result in a logged error and canned HTTP response | |
|
583 | ||
|
584 | $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS | |
|
585 | $ hg --config extensions.hgweberror=$TESTDIR/hgweberror.py serve -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log | |
|
586 | $ cat hg.pid >> $DAEMON_PIDS | |
|
587 | ||
|
588 | $ $TESTDIR/get-with-headers.py localhost:$HGPORT 'raiseerror' transfer-encoding content-type | |
|
589 | 500 Internal Server Error | |
|
590 | transfer-encoding: chunked | |
|
591 | ||
|
592 | Internal Server Error (no-eol) | |
|
593 | [1] | |
|
594 | ||
|
595 | $ head -1 errors.log | |
|
596 | .* Exception happened during processing request '/raiseerror': (re) | |
|
597 | ||
|
598 | Uncaught exception after partial content sent | |
|
599 | ||
|
600 | $ $TESTDIR/get-with-headers.py localhost:$HGPORT 'raiseerror?partialresponse=1' transfer-encoding content-type | |
|
601 | 200 Script output follows | |
|
602 | transfer-encoding: chunked | |
|
603 | content-type: text/plain | |
|
604 | ||
|
605 | partial content | |
|
606 | Internal Server Error (no-eol) | |
|
607 | ||
|
582 | 608 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now