Patchwork [3,of,3,hglib] client: include stderr message in ServerError on initial communication failure

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 9, 2015, 3:35 p.m.
Message ID <2e7c77b28e75bbab3af1.1441812917@mimosa>
Download mbox | patch
Permalink /patch/10440/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 9, 2015, 3:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1441633547 -32400
#      Mon Sep 07 22:45:47 2015 +0900
# Node ID 2e7c77b28e75bbab3af129722f5dcb822e02e589
# Parent  b2c14bdc8741742d3c9d22afaabfdecb8622d7f5
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.
Matt Mackall - Sept. 9, 2015, 8:59 p.m.
On Thu, 2015-09-10 at 00:35 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1441633547 -32400
> #      Mon Sep 07 22:45:47 2015 +0900
> # Node ID 2e7c77b28e75bbab3af129722f5dcb822e02e589
> # Parent  b2c14bdc8741742d3c9d22afaabfdecb8622d7f5
> client: include stderr message in ServerError on initial communication failure

These are pushed, thanks.

Patch

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -190,7 +190,12 @@  class hgclient(object):
             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 --git a/tests/test-hglib.py b/tests/test-hglib.py
--- a/tests/test-hglib.py
+++ b/tests/test-hglib.py
@@ -12,3 +12,14 @@  class test_hglib(common.basetest):
         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))