mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-26 03:13:45 +03:00
Make BufferError message more useful
This commit is contained in:
parent
0235fce99c
commit
200d1d67be
|
@ -23,6 +23,7 @@ class BinaryReader:
|
||||||
'Either bytes or a stream must be provided')
|
'Either bytes or a stream must be provided')
|
||||||
|
|
||||||
self.reader = BufferedReader(self.stream)
|
self.reader = BufferedReader(self.stream)
|
||||||
|
self._last = None # Should come in handy to spot -404 errors
|
||||||
|
|
||||||
# region Reading
|
# region Reading
|
||||||
|
|
||||||
|
@ -57,8 +58,12 @@ class BinaryReader:
|
||||||
"""Read the given amount of bytes"""
|
"""Read the given amount of bytes"""
|
||||||
result = self.reader.read(length)
|
result = self.reader.read(length)
|
||||||
if len(result) != length:
|
if len(result) != length:
|
||||||
raise BufferError('No more data left to read')
|
raise BufferError(
|
||||||
|
'No more data left to read (need {}, got {}: {}); last read {}'
|
||||||
|
.format(length, len(result), repr(result), repr(self._last))
|
||||||
|
)
|
||||||
|
|
||||||
|
self._last = result
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_bytes(self):
|
def get_bytes(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user