Mercurial > public > mercurial-scm > hg
comparison hgext/chgserver.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 | 945e9516b435 |
children | 0747ef2c4ab2 |
comparison
equal
deleted
inserted
replaced
28510:ade330deb39a | 28511:ff5f923fca3c |
---|---|
523 # process pass kernel "is_current_pgrp_orphaned" check so signals like | 523 # process pass kernel "is_current_pgrp_orphaned" check so signals like |
524 # SIGTSTP, SIGTTIN, SIGTTOU are not ignored. | 524 # SIGTSTP, SIGTTIN, SIGTTOU are not ignored. |
525 os.setpgid(0, 0) | 525 os.setpgid(0, 0) |
526 ui = self.server.ui | 526 ui = self.server.ui |
527 repo = self.server.repo | 527 repo = self.server.repo |
528 sv = chgcmdserver(ui, repo, self.rfile, self.wfile, self.connection, | 528 sv = None |
529 self.server.hashstate, self.server.baseaddress) | 529 try: |
530 try: | 530 sv = chgcmdserver(ui, repo, self.rfile, self.wfile, self.connection, |
531 self.server.hashstate, self.server.baseaddress) | |
531 try: | 532 try: |
532 sv.serve() | 533 sv.serve() |
533 # handle exceptions that may be raised by command server. most of | 534 # handle exceptions that may be raised by command server. most of |
534 # known exceptions are caught by dispatch. | 535 # known exceptions are caught by dispatch. |
535 except error.Abort as inst: | 536 except error.Abort as inst: |
542 finally: | 543 finally: |
543 sv.cleanup() | 544 sv.cleanup() |
544 except: # re-raises | 545 except: # re-raises |
545 # also write traceback to error channel. otherwise client cannot | 546 # also write traceback to error channel. otherwise client cannot |
546 # see it because it is written to server's stderr by default. | 547 # see it because it is written to server's stderr by default. |
547 traceback.print_exc(file=sv.cerr) | 548 if sv: |
549 cerr = sv.cerr | |
550 else: | |
551 cerr = commandserver.channeledoutput(self.wfile, 'e') | |
552 traceback.print_exc(file=cerr) | |
548 raise | 553 raise |
549 | 554 |
550 def _tempaddress(address): | 555 def _tempaddress(address): |
551 return '%s.%d.tmp' % (address, os.getpid()) | 556 return '%s.%d.tmp' % (address, os.getpid()) |
552 | 557 |