Skip to content

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Aug 26, 2025

Found in #1864

Also combine like exceptions, within the catch block.

Summary by Sourcery

Unify exception handling in the CLI by grouping similar errors and including KeyError in the invalid input catch block

Bug Fixes:

  • Handle KeyError exceptions to prevent unhandled errors

Enhancements:

  • Combine ConnectionError, IndexError, KeyError, and ValueError into a single invalid argument catch block
  • Combine NotImplementedError and RuntimeError into a single not supported features catch block

Copy link
Contributor

sourcery-ai bot commented Aug 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors exception handling in cli.py by adding KeyError to the primary catch, grouping similar exceptions into tuple-based except blocks, and removing redundant individual handlers for streamlined error processing.

File-Level Changes

Change Details Files
Grouped ConnectionError, IndexError, KeyError, and ValueError into a single except block
  • Expanded the first except to catch a tuple of errors
  • Removed separate except handlers for KeyError, ConnectionError, and ValueError
ramalama/cli.py
Merged NotImplementedError and RuntimeError into one handler
  • Combined these two exceptions into a single tuple-based except
ramalama/cli.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @rhatdan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the exception handling within the eprint function in ramalama/cli.py. It consolidates several exception types that previously had separate except blocks but shared similar error handling logic, specifically addressing a KeyError issue found in containers/ramalama/issues/1864 by ensuring it's caught and handled consistently with other input-related errors.

Highlights

  • Exception Consolidation: Grouped KeyError, ConnectionError, IndexError, and ValueError into a single except block, all now exiting with errno.EINVAL. This streamlines error handling for these related issues.
  • Runtime Error Handling: Combined NotImplementedError and RuntimeError into a single except block, both now exiting with errno.ENOTSUP, improving consistency.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the exception handling in ramalama/cli.py by grouping similar exception types, which improves code readability and maintainability. My review points out that this consolidation changes the exit code for KeyError from 1 to errno.EINVAL. This is a behavioral change that might have been overlooked and could impact users relying on the specific exit code. I've provided a suggestion to restore the original behavior if this change was unintentional.

Found in containers#1864

Also combine like exceptions, within the catch block.

Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan
Copy link
Member Author

rhatdan commented Aug 26, 2025

@engelmi PTAL

@engelmi
Copy link
Member

engelmi commented Aug 27, 2025

/packit retest-failed
/packit build

@engelmi
Copy link
Member

engelmi commented Aug 27, 2025

/packit rebuild-failed

Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

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

LGTM

@engelmi engelmi merged commit d1cc571 into containers:main Aug 27, 2025
56 of 61 checks passed
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