Mercurial > public > mercurial-scm > hg-stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
28510:ade330deb39a | 28511:ff5f923fca3c |
---|---|
336 | 336 |
337 class _requesthandler(SocketServer.StreamRequestHandler): | 337 class _requesthandler(SocketServer.StreamRequestHandler): |
338 def handle(self): | 338 def handle(self): |
339 ui = self.server.ui | 339 ui = self.server.ui |
340 repo = self.server.repo | 340 repo = self.server.repo |
341 sv = server(ui, repo, self.rfile, self.wfile) | 341 sv = None |
342 try: | 342 try: |
343 sv = server(ui, repo, self.rfile, self.wfile) | |
343 try: | 344 try: |
344 sv.serve() | 345 sv.serve() |
345 # handle exceptions that may be raised by command server. most of | 346 # handle exceptions that may be raised by command server. most of |
346 # known exceptions are caught by dispatch. | 347 # known exceptions are caught by dispatch. |
347 except error.Abort as inst: | 348 except error.Abort as inst: |
352 except KeyboardInterrupt: | 353 except KeyboardInterrupt: |
353 pass | 354 pass |
354 except: # re-raises | 355 except: # re-raises |
355 # also write traceback to error channel. otherwise client cannot | 356 # also write traceback to error channel. otherwise client cannot |
356 # see it because it is written to server's stderr by default. | 357 # see it because it is written to server's stderr by default. |
357 traceback.print_exc(file=sv.cerr) | 358 if sv: |
359 cerr = sv.cerr | |
360 else: | |
361 cerr = channeledoutput(self.wfile, 'e') | |
362 traceback.print_exc(file=cerr) | |
358 raise | 363 raise |
359 | 364 |
360 class unixservice(object): | 365 class unixservice(object): |
361 """ | 366 """ |
362 Listens on unix domain socket and forks server per connection | 367 Listens on unix domain socket and forks server per connection |