Browse Source

When the client hangs up unexpectedly, forwars stderr lines.

Jelmer Vernooij 4 years ago
parent
commit
e3e68dcecc
2 changed files with 12 additions and 10 deletions
  1. 10 9
      dulwich/client.py
  2. 2 1
      dulwich/errors.py

+ 10 - 9
dulwich/client.py

@@ -736,15 +736,16 @@ def check_wants(wants, refs):
         raise InvalidWants(missing)
 
 
-def remote_error_from_stderr(stderr):
+def _remote_error_from_stderr(stderr):
     if stderr is None:
-        return HangupException()
+        raise HangupException()
+    lines = list(stderr.readlines())
     for line in stderr.readlines():
         if line.startswith(b'ERROR: '):
-            return GitProtocolError(
+            raise GitProtocolError(
                 line[len(b'ERROR: '):].decode('utf-8', 'replace'))
-        return GitProtocolError(line.decode('utf-8', 'replace'))
-    return HangupException()
+        raise GitProtocolError(line.decode('utf-8', 'replace'))
+    raise HangupException(lines)
 
 
 class TraditionalGitClient(GitClient):
@@ -799,7 +800,7 @@ class TraditionalGitClient(GitClient):
             try:
                 old_refs, server_capabilities = read_pkt_refs(proto)
             except HangupException:
-                raise remote_error_from_stderr(stderr)
+                _remote_error_from_stderr(stderr)
             negotiated_capabilities = \
                 self._negotiate_receive_pack_capabilities(server_capabilities)
             if CAPABILITY_REPORT_STATUS in negotiated_capabilities:
@@ -878,7 +879,7 @@ class TraditionalGitClient(GitClient):
             try:
                 refs, server_capabilities = read_pkt_refs(proto)
             except HangupException:
-                raise remote_error_from_stderr(stderr)
+                _remote_error_from_stderr(stderr)
             negotiated_capabilities, symrefs, agent = (
                     self._negotiate_upload_pack_capabilities(
                             server_capabilities))
@@ -915,7 +916,7 @@ class TraditionalGitClient(GitClient):
             try:
                 refs, _ = read_pkt_refs(proto)
             except HangupException:
-                raise remote_error_from_stderr(stderr)
+                _remote_error_from_stderr(stderr)
             proto.write_pkt_line(None)
             return refs
 
@@ -935,7 +936,7 @@ class TraditionalGitClient(GitClient):
             try:
                 pkt = proto.read_pkt_line()
             except HangupException:
-                raise remote_error_from_stderr(stderr)
+                _remote_error_from_stderr(stderr)
             if pkt == b"NACK\n":
                 return
             elif pkt == b"ACK\n":

+ 2 - 1
dulwich/errors.py

@@ -133,9 +133,10 @@ class UpdateRefsError(GitProtocolError):
 class HangupException(GitProtocolError):
     """Hangup exception."""
 
-    def __init__(self):
+    def __init__(self, stderr_lines=None):
         super(HangupException, self).__init__(
             "The remote server unexpectedly closed the connection.")
+        self.stderr_lines = stderr_lines
 
 
 class UnexpectedCommandError(GitProtocolError):