scott-griffiths/bitstring

4.2.x: Reading past the end of stream no longer raises ReadError

Closed this issue · 2 comments

In earlier versions, reading past the end of a BitStream raised a ReadError.

Now, it seems that it raises a ValueError. Example:

  File "/home/eric/ros_workspace/src/ros_acomms/ros_acomms/src/acomms_codecs/ros_packet_codec.py", line 147, in decode_payload
    id = payload_bits.read('uint:8')
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bitstream.py", line 349, in read
    val = dtype.read_fn(self, self._pos)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/dtypes.py", line 297, in read_fn
    return self.get_fn(bs[start:start + length])
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/dtypes.py", line 285, in allowed_length_checked_get_fn
    return get_fn(bs)
  File "/home/eric/.local/lib/python3.8/site-packages/bitstring/bits.py", line 661, in _getuint
    raise bitstring.InterpretError("Cannot interpret a zero length bitstring as an integer.")
ValueError: Cannot interpret a zero length bitstring as an integer.

From the documentation, ReadError is the intended behavior:

Reads from current bit position pos in the bitstring according the format string and returns a single result. If not enough bits are available then a ReadError is raised.

Hi, thanks for the bug report.

Yes that looks like an unintended change. I'll fix it in the next point release.

Thanks again.

bitstring 4.2.2 is now released. 🎉