Clean up SegmentError messages

Since we already deducted the full length of the chunk from bytes_left
before raising the too-many-bytes error, the value in the error message
was always negative, like

    Too many bytes for /v1/AUTH_test/c%3Fwith-question-mark/dlo;
    truncating in /v1/AUTH_test/c with -27244 bytes left

In the not-enough-bytes case, we may as well mention how many more bytes
we were expecting.

Change-Id: I155ed1837d40b4aaf929452b830f03c1daab0af7
This commit is contained in:
Tim Burke 2018-04-12 20:59:24 +00:00
parent 0a6f0d615c
commit f1bbb5f980

View File

@ -515,11 +515,11 @@ class SegmentedIterable(object):
'Too many bytes for %(name)s; truncating in '
'%(seg)s with %(left)d bytes left' %
{'name': self.name, 'seg': seg_name,
'left': bytes_left})
'left': -bytes_left})
if bytes_left:
raise SegmentError(
'Not enough bytes for %s; closing connection' % self.name)
raise SegmentError('Expected another %d bytes for %s; '
'closing connection' % (bytes_left, self.name))
def _time_limited_iter(self):
# Makes sure a GET response doesn't take more than self.max_get_time