Patchwork [2,of,3,hglib] _readchannel: if a read failure is due to a broken server, report that

login
register
mail settings
Submitter Augie Fackler
Date Dec. 10, 2017, 5:54 p.m.
Message ID <a58ab92c962337fe1770.1512928493@imladris.local>
Download mbox | patch
Permalink /patch/26199/
State Accepted
Headers show

Comments

Augie Fackler - Dec. 10, 2017, 5:54 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1512928257 18000
#      Sun Dec 10 12:50:57 2017 -0500
# Node ID a58ab92c962337fe177001ec17df0efc673e8279
# Parent  fd22223e0c7b22d8807e30f96f734d10c59f4433
_readchannel: if a read failure is due to a broken server, report that

We can end up in this codepath if the specified hg binary fails to
start, and we're better off reporting that than the fact that we got
no response.

Patch

diff --git a/hglib/client.py b/hglib/client.py
--- a/hglib/client.py
+++ b/hglib/client.py
@@ -147,7 +147,10 @@  class hgclient(object):
     def _readchannel(self):
         data = self.server.stdout.read(hgclient.outputfmtsize)
         if not data:
-            self.close()
+            ret, serr = self._close()
+            if ret != 0:
+                raise error.ServerError('server exited with status %d: %s'
+                                        % (ret, serr.strip()))
             raise error.ResponseError('no response received from server')
         channel, length = struct.unpack(hgclient.outputfmt, data)
         if channel in b('IL'):
@@ -271,6 +274,10 @@  class hgclient(object):
             self.close()
             raise
         except error.ServerError:
+            if self.server is None:
+                # server is already closed, hopefully the ServerError
+                # we got has enough information.
+                raise
             ret, serr = self._close()
             raise error.ServerError('server exited with status %d: %s'
                                     % (ret, serr.strip()))