Mercurial > python-hglib
changeset 169:e6589149b2c8 1.9
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.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 07 Sep 2015 22:45:47 +0900 |
parents | d71bd813c9d7 |
children | ffca01835a7c |
files | hglib/client.py tests/test-hglib.py |
diffstat | 2 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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):
--- 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))