Skip to content

Conversation

@rajatsingh535
Copy link

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!

@rajatsingh535
Copy link
Author

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.

@pombredanne
Copy link
Member

Thanks! Simple and clean. Can you amend your commit to add a DCO signoff?

Signed-off-by: RAJATSINGH <rajat.singh20242@lpu.in>
@rajatsingh535 rajatsingh535 force-pushed the fix/175-replace-asserts branch from 033d7f1 to 5fb35eb Compare September 15, 2025 06:13
@rajatsingh535
Copy link
Author

@pombredanne

Hello,
I have amended the commit to include the DCO sign-off as requested. The DCO check should now be passing.

Thank you for your guidance.

@rajatsingh535
Copy link
Author

Hi @pombredanne, I’ve added the DCO sign-off and confirmed that the checks are passing now.
Looks like one workflow is awaiting approval. Could you please approve it when you get a chance?

Thanks again.

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

Successfully merging this pull request may close these issues.

2 participants