# HG changeset patch # User Anton Shestakov # Date 2018-09-08 15:57:07 # Node ID 1fc39367eafda83e757d99cc16164c0fbc8fd63a # Parent 77a2f6d805f2044e7fe5c85ed217070a4dc6de8d httppeer: calculate total expected bytes correctly User-facing error messages that handled httplib.IncompleteRead errors in Mercurial used to look like this: abort: HTTP request error (incomplete response; expected 3 bytes got 1) But the errors that are being handled underneath the UI look like this: IncompleteRead(1 bytes read, 3 more expected) I.e. the error actually counts total number of expected bytes minus bytes already received. Before, users could see weird messages like "expected 10 bytes got 10", while in reality httplib expected 10 _more_ bytes (20 in total). diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -84,9 +84,10 @@ def _wraphttpresponse(resp): except httplib.IncompleteRead as e: # e.expected is an integer if length known or None otherwise. if e.expected: + got = len(e.partial) + total = e.expected + got msg = _('HTTP request error (incomplete response; ' - 'expected %d bytes got %d)') % (e.expected, - len(e.partial)) + 'expected %d bytes got %d)') % (total, got) else: msg = _('HTTP request error (incomplete response)') diff --git a/tests/test-http-bad-server.t b/tests/test-http-bad-server.t --- a/tests/test-http-bad-server.t +++ b/tests/test-http-bad-server.t @@ -275,7 +275,7 @@ Server sends an incomplete capabilities $ cat hg.pid > $DAEMON_PIDS $ hg clone http://localhost:$HGPORT/ clone - abort: HTTP request error (incomplete response; expected 416 bytes got 20) + abort: HTTP request error (incomplete response; expected 436 bytes got 20) (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] @@ -600,7 +600,7 @@ Server sends partial bundle2 header magi $ hg clone http://localhost:$HGPORT/ clone requesting all changes - abort: HTTP request error (incomplete response; expected 1 bytes got 3) + abort: HTTP request error (incomplete response; expected 4 bytes got 3) (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] @@ -624,7 +624,7 @@ Server sends incomplete bundle2 stream p $ hg clone http://localhost:$HGPORT/ clone requesting all changes - abort: HTTP request error (incomplete response; expected 1 bytes got 3) + abort: HTTP request error (incomplete response; expected 4 bytes got 3) (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] @@ -733,7 +733,7 @@ Server stops after bundle2 part payload adding changesets transaction abort! rollback completed - abort: HTTP request error (incomplete response; expected 459 bytes got 7) + abort: HTTP request error (incomplete response; expected 466 bytes got 7) (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] @@ -799,7 +799,7 @@ Server stops sending after 0 length payl added 1 changesets with 1 changes to 1 files transaction abort! rollback completed - abort: HTTP request error (incomplete response; expected 23 bytes got 9) + abort: HTTP request error (incomplete response; expected 32 bytes got 9) (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255]