Skip to content

MGMT-21113: Return less on error#44

Merged
openshift-merge-bot[bot] merged 2 commits intoopenshift-assisted:masterfrom
carbonin:return-less-on-error
Jul 30, 2025
Merged

MGMT-21113: Return less on error#44
openshift-merge-bot[bot] merged 2 commits intoopenshift-assisted:masterfrom
carbonin:return-less-on-error

Conversation

@carbonin
Copy link
Copy Markdown
Collaborator

@carbonin carbonin commented Jul 28, 2025

Before this, it was possible that internal implementation details in error messages would be returned to the LLM when the MCP server encountered an error. This isn't what we want because users shouldn't get messages from the LLM about the application.

This continues to log issues, while returning just a minimal response message to the agent on error.

https://issues.redhat.com/browse/MGMT-21113

Summary by CodeRabbit

  • Refactor
    • Centralized and improved error handling for all Assisted Service API operations, delivering clearer and more consistent error messages.
  • Bug Fixes
    • Enhanced exception management to ensure API errors are reported in a user-friendly and reliable manner.
  • Tests
    • Updated tests to validate the new error handling approach and confirm that user-facing error messages remain accurate and informative.

Before this, it was possible that internal implementation details in
error messages would be returned to the LLM when the MCP server
encountered an error. This isn't what we want because users shouldn't
get messages from the LLM about the application.

This continues to log issues, while returning just a minimal response
message to the agent on error.

https://issues.redhat.com/browse/MGMT-21113
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 28, 2025
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 28, 2025

@carbonin: This pull request references MGMT-21113 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Before this, it was possible that internal implementation details in error messages would be returned to the LLM when the MCP server encountered an error. This isn't what we want because users shouldn't get messages from the LLM about the application.

This continues to log issues, while returning just a minimal response message to the agent on error.

https://issues.redhat.com/browse/MGMT-21113

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot requested review from eranco74 and omertuc July 28, 2025 20:50
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 28, 2025

Walkthrough

Centralized exception handling for the Assisted Service client is introduced by implementing a sanitize_exceptions decorator and a custom AssistedServiceAPIError. All public async API methods in InventoryClient are now decorated, replacing individual try-except blocks. Tests are updated to expect the new exception type, and a new exceptions module is added.

Changes

Cohort / File(s) Change Summary
Exception Handling Refactor
service_client/assisted_service_api.py
Removed per-method try-except blocks for API calls; applied @sanitize_exceptions decorator to all public async methods; updated imports to use new exception handling.
New Exception Module
service_client/exceptions.py
Introduced AssistedServiceAPIError class and sanitize_exceptions decorator for centralized, consistent exception handling and logging.
Test Updates for Exception Handling
tests/test_assisted_service_api.py
Modified tests to expect AssistedServiceAPIError instead of ApiException or ValueError; updated assertions and imports accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant InventoryClient
    participant AssistedServiceAPI
    participant sanitize_exceptions

    Test->>InventoryClient: Call public async method (e.g., get_cluster)
    InventoryClient->>sanitize_exceptions: Method wrapped by decorator
    sanitize_exceptions->>AssistedServiceAPI: Perform API call
    AssistedServiceAPI-->>sanitize_exceptions: Success or Exception
    alt ApiException or Exception occurs
        sanitize_exceptions-->>Test: Raise AssistedServiceAPIError
    else Success
        sanitize_exceptions-->>Test: Return result
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • MGMT-20958: Logging and error handling #12: Refactors exception handling in InventoryClient methods by replacing explicit try-except blocks with a centralized @sanitize_exceptions decorator; related as both modify error handling approaches in these methods.

Suggested labels

lgtm

Poem

A rabbit hopped through code so neat,
Wrapping errors in a central seat.
No more try-except in every place—
Just one decorator, full of grace!
Now tests and clients both agree:
Clean exceptions, bug-free glee!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38251e7 and 3621f22.

📒 Files selected for processing (3)
  • service_client/assisted_service_api.py (15 hunks)
  • service_client/exceptions.py (1 hunks)
  • tests/test_assisted_service_api.py (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • service_client/exceptions.py
  • tests/test_assisted_service_api.py
  • service_client/assisted_service_api.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Red Hat Konflux / assisted-service-mcp-saas-main-on-pull-request
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jul 28, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carbonin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 28, 2025
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 28, 2025

@carbonin: This pull request references MGMT-21113 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Before this, it was possible that internal implementation details in error messages would be returned to the LLM when the MCP server encountered an error. This isn't what we want because users shouldn't get messages from the LLM about the application.

This continues to log issues, while returning just a minimal response message to the agent on error.

https://issues.redhat.com/browse/MGMT-21113

Summary by CodeRabbit

  • Refactor
  • Improved error handling for all Assisted Service API operations, providing clearer and more consistent error messages.
  • Bug Fixes
  • Enhanced exception management to ensure API errors are reported in a user-friendly manner.
  • Tests
  • Updated tests to verify the new error handling behavior and ensure that user-facing error messages are accurate and informative.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Copy Markdown
Collaborator

@eranco74 eranco74 left a comment

Choose a reason for hiding this comment

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

Just a nit

Comment thread service_client/exceptions.py Outdated
"""

def decorator(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[T]]:
@wraps(func)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can do:
operation_name = func.__name__
And get rid of the peration_name: str in line 25

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nice, thanks. I'll do that

@carbonin carbonin force-pushed the return-less-on-error branch from 38251e7 to 3621f22 Compare July 29, 2025 19:30
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jul 29, 2025

@carbonin: This pull request references MGMT-21113 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "4.20.0" version, but no target version was set.

Details

In response to this:

Before this, it was possible that internal implementation details in error messages would be returned to the LLM when the MCP server encountered an error. This isn't what we want because users shouldn't get messages from the LLM about the application.

This continues to log issues, while returning just a minimal response message to the agent on error.

https://issues.redhat.com/browse/MGMT-21113

Summary by CodeRabbit

  • Refactor
  • Centralized and improved error handling for all Assisted Service API operations, delivering clearer and more consistent error messages.
  • Bug Fixes
  • Enhanced exception management to ensure API errors are reported in a user-friendly and reliable manner.
  • Tests
  • Updated tests to validate the new error handling approach and confirm that user-facing error messages remain accurate and informative.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link
Copy Markdown
Collaborator

@eranco74 eranco74 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 30, 2025
@openshift-merge-bot openshift-merge-bot Bot merged commit 2c3e194 into openshift-assisted:master Jul 30, 2025
15 checks passed
@carbonin carbonin deleted the return-less-on-error branch July 30, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants