mercurial/hgweb/server.py
changeset 41476 9b2b8794f801
parent 41452 52a4a3e7cc6a
child 41493 6bbb12cba5a8
--- a/mercurial/hgweb/server.py	Tue Jan 29 11:51:19 2019 -0800
+++ b/mercurial/hgweb/server.py	Wed Jan 30 11:44:34 2019 -0800
@@ -101,9 +101,8 @@
         try:
             self.do_write()
         except Exception:
-            self._start_response(r"500 Internal Server Error", [])
-            self._write(b"Internal Server Error")
-            self._done()
+            # I/O below could raise another exception. So log the original
+            # exception first to ensure it is recorded.
             tb = r"".join(traceback.format_exception(*sys.exc_info()))
             # We need a native-string newline to poke in the log
             # message, because we won't get a newline when using an
@@ -112,6 +111,10 @@
             self.log_error(r"Exception happened during processing "
                            r"request '%s':%s%s", self.path, newline, tb)
 
+            self._start_response(r"500 Internal Server Error", [])
+            self._write(b"Internal Server Error")
+            self._done()
+
     def do_PUT(self):
         self.do_POST()