guarddog icon indicating copy to clipboard operation
guarddog copied to clipboard

analyzer.py exception handling and refactor suggestion

Open sandekap opened this issue 10 months ago • 2 comments

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

sandekap avatar Feb 28 '25 20:02 sandekap

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 avatar Mar 03 '25 10:03 sobregosodd

@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.

sandekap avatar Mar 05 '25 14:03 sandekap

Closing this issue. We can continue to consider the proposed changes in the forthcoming PR.

ikretz avatar Jul 11 '25 14:07 ikretz