# HG changeset patch # User Yuya Nishihara # Date 1441633547 -32400 # Node ID e6589149b2c8547a8154083ebfdb882e3225d74c # Parent d71bd813c9d73a8a27bc46cce5653d6f450549af client: include stderr message in ServerError on initial communication failure If _readhello() raises ServerError, the server must be unusable. So we can terminate it to get status code and error message. diff -r d71bd813c9d7 -r e6589149b2c8 hglib/client.py --- a/hglib/client.py Mon Sep 07 22:32:12 2015 +0900 +++ b/hglib/client.py Mon Sep 07 22:45:47 2015 +0900 @@ -190,7 +190,12 @@ raise ValueError('server already open') self.server = util.popen(self._args, self._env) - self._readhello() + try: + self._readhello() + except error.ServerError: + ret, serr = self._close() + raise error.ServerError('server exited with status %d: %s' + % (ret, serr.strip())) return self def close(self): diff -r d71bd813c9d7 -r e6589149b2c8 tests/test-hglib.py --- a/tests/test-hglib.py Mon Sep 07 22:32:12 2015 +0900 +++ b/tests/test-hglib.py Mon Sep 07 22:45:47 2015 +0900 @@ -12,3 +12,14 @@ common.basetest.setUp(self) client2 = hglib.open() self.client.close() + + def test_open_nonexistent(self): + # setup stuff necessary for basetest.tearDown() + self.clients = [] + self._oldopen = hglib.client.hgclient.open + try: + self.clients.append(hglib.open('inexistent')) + # hg 3.5 can't report error (fixed by 7332bf4ae959) + #self.fail('ServerError not raised') + except hglib.error.ServerError as inst: + self.assertTrue('inexistent' in str(inst))