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

Pass a partially received response in the ValueError exception. #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions umodbus/client/serial/redundancy_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ def validate_crc(msg):
"""
if not struct.unpack('<H', get_crc(msg[:-2])) ==\
struct.unpack('<H', msg[-2:]):
raise CRCError('CRC validation failed.')
raise CRCError(msg)


class CRCError(Exception):
""" Valid error to raise when CRC isn't correct. """
pass
"""CRC validation failed."""

def __str__(self):
return self.__doc__
2 changes: 1 addition & 1 deletion umodbus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ def recv_exactly(recv_fn, size):
response = b''.join(chunks)

if len(response) != size:
raise ValueError
raise ValueError(response)

return response