Skip to content

Commit

Permalink
Make BufferError message more useful
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Sep 18, 2017
1 parent 0235fce commit 200d1d6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion telethon/extensions/binary_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self, data=None, stream=None):
'Either bytes or a stream must be provided')

self.reader = BufferedReader(self.stream)
self._last = None # Should come in handy to spot -404 errors

# region Reading

Expand Down Expand Up @@ -57,8 +58,12 @@ def read(self, length):
"""Read the given amount of bytes"""
result = self.reader.read(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

def get_bytes(self):
Expand Down

0 comments on commit 200d1d6

Please sign in to comment.