Skip to content

Commit

Permalink
Wrap all urllib3 read ProtocolErrors as GitProtocolError
Browse files Browse the repository at this point in the history
  • Loading branch information
nanonyme committed Mar 13, 2024
1 parent 0eeeafc commit a5cc324
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,17 @@ def __repr__(self) -> str:
return f"{type(self).__name__}({self._base_url!r}, dumb={self.dumb!r})"


def _wrap_urllib3_exceptions(func):

def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except urllib3.exceptions.ProtocolError as error:
raise GitProtocolError(str(error)) from error

return wrapper


class Urllib3HttpGitClient(AbstractHttpGitClient):
def __init__(
self,
Expand Down Expand Up @@ -2308,7 +2319,7 @@ def _http_request(self, url, headers=None, data=None):
resp.redirect_location = resp.get_redirect_location()
else:
resp.redirect_location = resp_url if resp_url != url else ""
return resp, resp.read
return resp, _wrap_urllib3_exceptions(resp.read)


HttpGitClient = Urllib3HttpGitClient
Expand Down

0 comments on commit a5cc324

Please sign in to comment.