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

Server and client decoders handle exceptions differently #2259

Closed
alexrudd2 opened this issue Jul 23, 2024 · 1 comment · Fixed by #2260
Closed

Server and client decoders handle exceptions differently #2259

alexrudd2 opened this issue Jul 23, 2024 · 1 comment · Fixed by #2260

Comments

@alexrudd2
Copy link
Collaborator

ServerDecoder

def decode(self, message):
"""Decode a request packet.
:param message: The raw modbus request packet
:return: The decoded modbus message or None if error
"""
try:
return self._helper(message)
except ModbusException as exc:
Log.warning("Unable to decode request {}", exc)
return None

ClientDecoder

def decode(self, message):
"""Decode a response packet.
:param message: The raw packet to decode
:return: The decoded modbus message or None if error
"""
try:
return self._helper(message)
except ModbusException as exc:
Log.error("Unable to decode response {}", exc)
except Exception as exc: # pylint: disable=broad-except
Log.error("General exception: {}", exc)
return None

The generic except Exception was added a long time ago in 1.5.0

It doesn't seem right to have them differ; which is preferred?

@janiversen
Copy link
Collaborator

you are right, the first one is better (without the generic exception).

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

Successfully merging a pull request may close this issue.

2 participants