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

Explicitly check for missing endpoints #100

Merged
merged 1 commit into from
Jul 25, 2020

Conversation

rgov
Copy link
Contributor

@rgov rgov commented Jul 24, 2020

The ModbusFunction.execute implementations invoke the callable returned by route_map.match(). The code assumes that if no match is found, then when calling the resulting None object, a TypeError will be thrown, and so it catches the exception and throws a IllegalDataAddressError instead.

However, by handling all TypeError exceptions the code is disguising TypeErrors thrown in other conditions. This is too general an exception when the code is really trying to handle one specific case. For instance, it hides the fact that a route's endpoint function might be declared with the wrong number of arguments.

This patch changes those exception handlers to simply an if statement. As a bonus it reduces indentation and reduces the (cyclomatic) complexity of the code; there is no longer the potential for a sudden jump to an exception handler out of a loop.

@coveralls
Copy link

coveralls commented Jul 24, 2020

Coverage Status

Coverage decreased (-0.04%) to 95.824% when pulling 7527a56 on rgov:rzg/fix-exceptions into dcf35a1 on AdvancedClimateSystems:master.

Copy link
Collaborator

@OrangeTux OrangeTux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the PR! Also I like your good exploitation.

@OrangeTux OrangeTux merged commit 0faaf90 into AdvancedClimateSystems:master Jul 25, 2020
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 this pull request may close these issues.

3 participants