Skip to content

Explicitly check for missing endpoints#100

Merged
OrangeTux merged 1 commit into
AdvancedClimateSystems:masterfrom
rgov:rzg/fix-exceptions
Jul 25, 2020
Merged

Explicitly check for missing endpoints#100
OrangeTux merged 1 commit into
AdvancedClimateSystems:masterfrom
rgov:rzg/fix-exceptions

Conversation

@rgov

@rgov rgov commented Jul 24, 2020

Copy link
Copy Markdown
Contributor

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

coveralls commented Jul 24, 2020

Copy link
Copy Markdown

Coverage Status

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

@rgov rgov force-pushed the rzg/fix-exceptions branch from 0801ef6 to 7527a56 Compare July 24, 2020 20:39

@OrangeTux OrangeTux left a comment

Copy link
Copy Markdown
Collaborator

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