Skip to content

fix(gsutil): Add graceful error handling for missing gsutil #4833

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

Merged
merged 4 commits into from
Apr 14, 2025

Conversation

JigyasuRajput
Copy link
Contributor

Description

Fixes #4220

This PR improves error handling in osv_source.py by catching FileNotFoundError when gsutil is not found. Instead of failing with a cryptic error, the code now provides a user-friendly message prompting users to check their environment setup.

Changes Made

  • Added a find_gsutil() function to check for gsutil using shutil.which().
  • If gsutil is not found in the PATH, the function checks under sys.prefix/bin/gsutil.
  • If still missing, a FileNotFoundError is raised with a clear message.
  • Replaced all hardcoded "gsutil" calls with gsutil_path from the helper function.

Why This Change?

  • Users running cve-bin-tool without activating their virtual environment were facing an unclear error (FileNotFoundError: [Errno 2] No such file or directory: 'gsutil').
  • This issue has been reported multiple times, so adding better error messaging improves usability.
  • The fix aligns with the maintainer’s suggestion to provide a clearer error message rather than modifying the PATH.

@JigyasuRajput
Copy link
Contributor Author

Hey! @terriko,
I'm unsure why this test is failing—possibly due to a network issue, Could you help me verify if any action is needed on my end?

def find_gsutil():
gsutil_path = shutil.which("gsutil")
if gsutil_path is None:
gsutil_path = f"{sys.prefix}/bin/gsutil"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I've been debating the security implications of this one. I think adding a possible new path that the user hasn't set themselves is probably incorrect behaviour, even if in this case the path is probably not actually a problem and likely was already in the user's path options. Can you rework this so we're not adding to the search options beyond what shutil.which is going to find using the user's existing path settings?

@terriko terriko added awaiting submitter Need more information from submitter and removed awaiting CI labels Mar 4, 2025
@terriko
Copy link
Contributor

terriko commented Mar 4, 2025

Realized I could resolve my concern via the web interface, so I've done that and the tests will now re-run.

@terriko terriko added awaiting CI and removed awaiting submitter Need more information from submitter labels Mar 4, 2025
@JigyasuRajput
Copy link
Contributor Author

JigyasuRajput commented Mar 4, 2025

Realized I could resolve my concern via the web interface, so I've done that and the tests will now re-run.

ok! let me know if anything is required from my side, I would be happy to help!

@terriko
Copy link
Contributor

terriko commented Mar 5, 2025

Tests are re-running, but I think we're ready if they pass!

@JigyasuRajput
Copy link
Contributor Author

Tests are re-running, but I think we're ready if they pass!

i've fixed the flake8 (which was failing along with html network one), I think it should be fine now

@JigyasuRajput JigyasuRajput requested a review from terriko March 10, 2025 19:06
Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're ready to merge this one. Thank you for your patience!

@terriko terriko merged commit c7c51eb into intel:main Apr 14, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gsutil error
2 participants