diff mercurial/commandserver.py @ 28511:ff5f923fca3c

cmdserver: write early exception to 'e' channel in 'unix' mode In 'unix' mode, the server is typically detached from the console. Therefore a client couldn't see the exception that occurred while instantiating the server object. This patch tries to catch the early error and send it to 'e' channel even if the server isn't instantiated yet. This means the error may be sent before the initial hello message. So it's up to the client implementation whether to handle the early error message or error out as protocol violation. The error handling code is also copied to chgserver.py. I'll factor out them later if we manage to get chg passes the test suite.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Mar 2016 22:03:30 +0900
parents e7c9b59dbbcf
children d269e7db2f55
line wrap: on
line diff
--- a/mercurial/commandserver.py	Sun Mar 13 01:32:42 2016 +0530
+++ b/mercurial/commandserver.py	Sat Mar 12 22:03:30 2016 +0900
@@ -338,8 +338,9 @@
     def handle(self):
         ui = self.server.ui
         repo = self.server.repo
-        sv = server(ui, repo, self.rfile, self.wfile)
+        sv = None
         try:
+            sv = server(ui, repo, self.rfile, self.wfile)
             try:
                 sv.serve()
             # handle exceptions that may be raised by command server. most of
@@ -354,7 +355,11 @@
         except: # re-raises
             # also write traceback to error channel. otherwise client cannot
             # see it because it is written to server's stderr by default.
-            traceback.print_exc(file=sv.cerr)
+            if sv:
+                cerr = sv.cerr
+            else:
+                cerr = channeledoutput(self.wfile, 'e')
+            traceback.print_exc(file=cerr)
             raise
 
 class unixservice(object):