Skip to content

analyzer.py exception handling and refactor suggestion #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sandekap opened this issue Feb 28, 2025 · 2 comments
Open

analyzer.py exception handling and refactor suggestion #534

sandekap opened this issue Feb 28, 2025 · 2 comments

Comments

@sandekap
Copy link

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

@sobregosodd
Copy link
Contributor

sobregosodd commented Mar 3, 2025

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?

@sandekap
Copy link
Author

sandekap commented Mar 5, 2025

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

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

No branches or pull requests

2 participants