Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
EricGallimore opened this issue May 1, 2024 · 2 comments
Closed

Comments

@EricGallimore
Copy link

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.

@scott-griffiths
Copy link
Owner

Hi, thanks for the bug report.

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

Thanks again.

@scott-griffiths
Copy link
Owner

bitstring 4.2.2 is now released. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants