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 allTypeError 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.
Coverage decreased (-0.04%) to 95.824% when pulling 7527a566a071ef2f698c1f0713e0acc91f12cbfa on rgov:rzg/fix-exceptions into dcf35a1f9881d0d5ffa4a640d1242fdcb3491bd7 on AdvancedClimateSystems:master.
The
ModbusFunction.execute
implementations invoke the callable returned byroute_map.match()
. The code assumes that if no match is found, then when calling the resultingNone
object, aTypeError
will be thrown, and so it catches the exception and throws aIllegalDataAddressError
instead.However, by handling all
TypeError
exceptions the code is disguisingTypeError
s 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.