Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Enable bare except checking #45389
if generally a bad thing to do in Python. It catches unexpected things like sys.exit() and KeyboardInterrupt. Catching Exception
At the moment, each individual site has not been reviewed to see if there is a reason to catch sys.exit and KeyBoardInterrupt. I would like to get feedback from the other devs about areas which do not need review (I believe that modules, for instance, should never be catching those. And, in fact, if they are, then there's very likely a bug in the code since AnsibleModule.exit_json and AnsibleModule.fail_json call sys.exit. If there's an bare exception handler around code which calls fail_json fail_json won't trigger correctly) Once we know which areas need review, I can review those pieces to make sure we don't need to explicitly catch some other exceptions in the port.
This should go in at the beginning of the 2.8 development cycle. So within the next few weeks.
Risk reward analysis:
(KeyboardInterrupt shouldn't be either a pro or con module side as there shouldn't be a way to generate that module-side).
referenced this pull request
Sep 14, 2018
@abadger How do you want to move this forward? It might be easier to enable the rule, add the necessary per-file skip entries and then submit separate PRs to fix the issues. Splitting up the fixes into multiple PRs would allow them to be grouped as needed to facilitate reviews by the appropriate people and keep slower reviews from holding up fixes for ones we're able to expedite.
I'd like to figure out the subset of this that can be fixed without input from other people because it's deemed safe or because it is code under the core teams responsibility anyway. Then fixing those and implementing the ship for only those files that remain. Leaving it up to other people to make changes won't make quick progress so I'm loathe to just leave that.
Module side we probably should fix everything that's using bare except because it's likely that as we revamp basic.py, bare except will end up catching sys.exit/SystemExit in now instances... Fail_json won't be limited to places that have access to a module so it will become even more of a trip hazard than it currently is