-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix(config/html): handle encoding issues and improve error handling in config and HTML file loading functions #4203
fix(config/html): handle encoding issues and improve error handling in config and HTML file loading functions #4203
Conversation
prowler/config/config.py
Outdated
except Exception as e: | ||
logger.critical(f"{e.__class__.__name__}[{e.__traceback__.tb_lineno}] -- {e}") | ||
|
||
sys.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the sys.exit(1)
should happen inside each exception right?
prowler/lib/outputs/html/html.py
Outdated
except Exception as e: | ||
logger.critical(f"{e.__class__.__name__}[{e.__traceback__.tb_lineno}] -- {e}") | ||
|
||
sys.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvements! @lshw54 Could you please review my comments? 🚀
Thanks!!I have made the changes to move |
Could you have a look to the tests? It seems that flake8 it's failing. Using pre-commit should be enough https://docs.prowler.com/projects/prowler-open-source/en/latest/developer-guide/introduction/ |
All pre-commit run result is passed |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4203 +/- ##
==========================================
- Coverage 86.66% 86.61% -0.06%
==========================================
Files 818 818
Lines 25674 25691 +17
==========================================
+ Hits 22251 22252 +1
- Misses 3423 3439 +16 ☔ View full report in Codecov by Sentry. |
Hi @pedrooot Thanks for your comment, it seems that I added some new comments and optimized a small portion of the code which resulted in a drop in coverage. |
True, don't worry about that. Btw we are reviewing it now 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lshw54, thanks for this fix!
Could you please change the log level to error and not exiting in those new errors? I don't think it could be a reason to exit Prowler execution since the scan can still continue.
I have made the requested changes. The log level has been changed to |
Thanks for the changes @lshw54 ! I also change the error messages to follow our pattern. |
…n config and HTML file loading functions (#4203) Co-authored-by: Sergio <sergio@prowler.com>
…n config and HTML file loading functions (#4203) Co-authored-by: Sergio <sergio@prowler.com>
Context
This pull request addresses issues related to file encoding and error handling in configuration file loading functions (
load_and_validate_config_file
andload_and_validate_fixer_config_file
) and the HTML output generation function (fill_html_overview_statistics
). The changes ensure that files are read and written with the correct encoding, preventingUnicodeDecodeError
.Description
Updated
load_and_validate_config_file
,load_and_validate_fixer_config_file
, andfill_html_overview_statistics
to open files withencoding='utf-8'
to ensure they are read and written correctly as UTF-8 encoded text.This change prevents
UnicodeDecodeError
caused by incorrect or unsupported file encodings.FileNotFoundError
,yaml.YAMLError
, andUnicodeDecodeError
in the configuration file loading functions.FileNotFoundError
andUnicodeDecodeError
in the HTML output generation function.stats.get()
infill_html_overview_statistics
to handle cases where keys might be missing.License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.