Fix #175: Replace unsafe assert statements with explicit exceptions#61
Fix #175: Replace unsafe assert statements with explicit exceptions#61rajatsingh535 wants to merge 1 commit intoaboutcode-org:mainfrom
Conversation
|
Hello @pombredanne, I have submitted this pull request to resolve issue #175. This is my first contribution to the project, and I'm very excited to be involved with AboutCode. I believe I have correctly addressed the issue by replacing the assert statements with proper if...raise exceptions. I would be very grateful if you could please take a look at my pull request and let me know if it is correct. I am hopeful it can be merged so I can continue to contribute. Thank you for your time. |
|
Thanks! Simple and clean. Can you amend your commit to add a DCO signoff? |
Signed-off-by: RAJATSINGH <rajat.singh20242@lpu.in>
033d7f1 to
5fb35eb
Compare
|
Hello, Thank you for your guidance. |
|
Hi @pombredanne, I’ve added the DCO sign-off and confirmed that the checks are passing now. Thanks again. |
Summary
This pull request addresses Issue #175. It replaces two assert statements with ValueError exceptions in src/container_inspector/cli.py to make the code more reliable.
Details
This pull request addresses a well-known best practice for error handling in Python. I noticed that the code was using assert statements for runtime validation of user input, which can lead to unexpected behavior in production.
To resolve this, I replaced those assert statements with explicit if...raise statements. This provides clear, consistent error handling that isn't dependent on the Python interpreter's optimization settings.
The specific code changes are as follows:
Change 1: In the _container_inspector_squash function, I replaced the assert statement with an if...raise block to ensure the program always validates the number of images.
Change 2: In the _container_inspector_dockerfile function, I made the same change to validate that a user specifies either JSON or CSV output.
Issue: #175
Checklist
[ ] I have verified the changes locally to ensure the new exceptions are raised correctly.
[ ] The changes follow the project's code style and best practices.
[ ] This is my first contribution to this project, and I've followed the contribution guidelines.
My Contribution Process
This is my first open-source contribution, and I am excited to be a part of the AboutCode community. My process involved:
Forking the repository to create my own copy.
Cloning my fork to work on my local machine.
Locating the cli.py file to address this specific issue.
Replacing the assert statements with if...raise to improve the code's robustness.
Committing the changes to a new branch linked to this issue.
I had a great time working on this and learned a lot about the contribution process—from forking and cloning to making the PR itself.
Thanks for the opportunity to contribute!