Skip to content

refactor(server): standardize tool error handling and status code mapping#2402

Merged
duwenxin99 merged 15 commits intomainfrom
err-api
Feb 12, 2026
Merged

refactor(server): standardize tool error handling and status code mapping#2402
duwenxin99 merged 15 commits intomainfrom
err-api

Conversation

@duwenxin99
Copy link
Contributor

@duwenxin99 duwenxin99 commented Feb 2, 2026

  • Detect errors and return error codes accordingly in the tool call handler functions.
  • Replace the old util.ErrUnauthorized with the new Toolbox error type.

@duwenxin99 duwenxin99 requested review from a team as code owners February 2, 2026 21:17
@duwenxin99 duwenxin99 changed the base branch from main to err February 2, 2026 21:17
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @duwenxin99, 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 significantly refactors the server's error handling logic, particularly for tool invocation and authentication-related issues. By introducing a new error hierarchy, the changes aim to standardize how errors are categorized and how corresponding HTTP status codes are determined and returned to clients. This improves the clarity and consistency of error responses across the server.

Highlights

  • Standardized Error Handling: Introduced a new structured error handling mechanism using ToolboxError, AgentError, and ClientServerError types to categorize and manage errors more effectively.
  • Improved HTTP Status Code Mapping: Refactored the server's API and MCP handlers to map internal errors to appropriate HTTP status codes (e.g., 401, 403, 500) based on the new error categories, moving away from string-based error matching.
  • Removed util.ErrUnauthorized: Replaced direct usage of the generic util.ErrUnauthorized error with the more specific util.NewClientServerError which includes an explicit HTTP status code.
  • Consistent Authentication Error Propagation: Ensured that authentication errors (401/403) are consistently handled and propagated, distinguishing between client credential issues and internal configuration problems.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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.

@duwenxin99 duwenxin99 assigned averikitsch and unassigned Yuan325 Feb 2, 2026
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 error handling to use a standardized, typed-error approach, which is a great improvement over string-based error checks. However, the implementation has introduced several critical and high-severity bugs. Specifically, there's an incorrect usage of errors.Is that will break authentication error checks, and multiple places where authorization checks are bypassed because of missing return statements. Additionally, error handling logic for tool.Invoke is incomplete, failing to handle errors that are not of the new custom ToolboxError type. These issues need to be addressed to ensure the server behaves correctly.

@Yuan325
Copy link
Contributor

Yuan325 commented Feb 3, 2026

Might want to merge this into a branch first instead of main if the tests will fail before refactoring other parts of Toolbox? Seems like the err branch is merging into main, and once that is merged, this PR will be updated to merge into main.

@duwenxin99
Copy link
Contributor Author

duwenxin99 commented Feb 4, 2026

Might want to merge this into a branch first instead of main if the tests will fail before refactoring other parts of Toolbox? Seems like the err branch is merging into main, and once that is merged, this PR will be updated to merge into main.

@Yuan325 I'm going to merge this refactor PR into this branch first: #2403

Base automatically changed from err to main February 12, 2026 13:34
@duwenxin99
Copy link
Contributor Author

/gemini review

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 and standardizes error handling across the server by introducing custom error types (AgentError, ClientServerError), aiming for improved maintainability and correctness. However, a critical security concern has been identified: the refactoring introduces a consistent pattern of exposing detailed internal error messages to the client for internal server errors (HTTP 500). This information exposure could be exploited by attackers to gain insights into the application's internal workings. Additionally, there are a few minor issues related to error message formatting and a potentially unhandled error.

@duwenxin99 duwenxin99 added the release candidate Use label to signal PR should be included in the next release. label Feb 12, 2026
- Use a generic `util.ProcessGcpError` for GCP tools
- Use a generic `util.ProcessGeneralError` for all other tools.

Error categorization in Invoke():
- Query errors default to AgentError.
- Missing/malformed parameters are AgentError.
- config, ctx, logger, source fetching errors are ClientServerError.
@duwenxin99 duwenxin99 requested review from a team as code owners February 12, 2026 15:36
@duwenxin99 duwenxin99 merged commit 32610d7 into main Feb 12, 2026
13 checks passed
@duwenxin99 duwenxin99 deleted the err-api branch February 12, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release candidate Use label to signal PR should be included in the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants