-
Notifications
You must be signed in to change notification settings - Fork 339
introduce NewToolResultErrorWithErr and update docs #140
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
Conversation
WalkthroughThe changes update error handling across two areas. The calculator tool now returns a standardized error message ("cannot divide by zero") using a structured error function instead of the default error generation. In parallel, the HTTP tool updates its error responses by replacing the use of generic formatting functions with a dedicated error function that appends detailed error context. Additionally, a new utility function has been added to create structured error results that include specific error details. Changes
Possibly related PRs
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
mcp/utils.go
Outdated
// NewToolResultErrorWithErr creates a new CallToolResult with an error message. | ||
// If an error is provided, its details will be appended to the text message. | ||
// Any errors that originate from the tool SHOULD be reported inside the result object. | ||
func NewToolResultErrorWithErr(text string, err error) *CallToolResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about NewToolResultErrorFromErr
instead? Semantically the same, maybe a bit more clearer.
We could even go NewToolResultErrorFrom
.
@deviantony Thanks for following up on this topic. The overall changes in this PR make sense to me, and I appreciate the effort to standardize error handling and clarify usage in the README. That said, I agree with @fabiante — |
This is a proposal for a follow-up on #87
It introduces a
NewToolResultErrorWithErr
function that takes an error as a parameter to aggregate it in the result.It also updates the documentation in the README to show when to use the regular
NewToolResultError
VSNewToolResultErrorWithErr
.@daimatz happy to hear your thoughts.
I've updated all errors handling to use this function because I don't think that there is a particular example in the README that covers a "regular" error raising, e.g.:
Summary by CodeRabbit