analyzer.py exception handling and refactor suggestion
In analyzer.py I noticed there could be an improvement on the exception handling potentially the following could be used instead try: # Code that may raise an exception except FileNotFoundError as e: log.error(f"File not found: {e}") except subprocess.CalledProcessError as e: log.error(f"Subprocess error: {e}") except json.JSONDecodeError as e: log.error(f"JSON decode error: {e}") except Exception as e: log.error(f"Unexpected error: {e}")
Also for aggregate_results potentially the refactored version could be more useful def aggregate_results(self, *results_dicts): aggregated = {"issues": 0, "errors": {}, "results": {}} for result in results_dicts: aggregated["issues"] += result["issues"] aggregated["errors"].update(result["errors"]) aggregated["results"].update(result["results"]) return aggregated
Hello @sandekap , thanks for the suggestions.
Also for aggregate_results potentially the refactored version could be more useful def aggregate_results(self, *results_dicts): aggregated = {"issues": 0, "errors": {}, "results": {}} for result in results_dicts: aggregated["issues"] += result["issues"] aggregated["errors"].update(result["errors"]) aggregated["results"].update(result["results"]) return aggregated
Why do you consider this is more useful than the current approach?
Would you like to submit a PR with the suggestions so we can better discuss each of them?
@sobregosodd Refactoring to reduce duplicate calls, has a lot of benefits. My main point is that it will enhance performance time and improve scalability. Other benefits include making bug fixing easier, reduce the complexity, improve readability, and make maintenance easier as the code is shorter which makes it easier to update as needed. I will submit a pull request shortly.
Closing this issue. We can continue to consider the proposed changes in the forthcoming PR.