fix(core): avoid error handling on cancelled requests to prevent crash#6039
fix(core): avoid error handling on cancelled requests to prevent crash#6039bulkypanda merged 4 commits intogoogle-gemini:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Summary of Changes
Hello @pwrwpw, 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 addresses a critical crash that occurred when users cancelled ongoing requests. The fix reorders the error handling logic to first check if a request has been aborted. By doing so, the system can gracefully handle cancellations, preventing attempts to access undefined error properties and ensuring a clean exit. This change maintains the correct handling of other error types, such as unauthorized access, while significantly improving the stability of request cancellation.
Highlights
- Crash Fix for Cancelled Requests: The core issue addressed is a crash that occurs when a user cancels a request, leading to attempts to access properties on an undefined error object within the error handling flow.
- Prioritized Cancellation Handling: The solution involves reordering the error handling logic to check for request cancellation (
signal.aborted) before attempting to process any potential errors. This ensures that if a request is aborted, the system gracefully exits and emits aUserCancelledevent without triggering further errors. - Preservation of Existing Error Handling: The change ensures that while cancelled requests are handled gracefully, the system still correctly processes and throws
UnauthorizedErrorinstances and reports other general errors as intended.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request addresses a critical crash that occurs when a request is cancelled. The fix involves moving the cancellation check to the beginning of the catch block, ensuring that cancelled requests are handled gracefully before any other error processing occurs. This prevents potential runtime errors from attempting to access properties on a malformed error object. The change is logical, robust, and correctly prioritizes user-initiated cancellations. I approve this change.
Head branch was pushed to by a user without write access
|
/gemini |
|
Hello @pwrwpw, I've received your request for a code review. Here's my assessment of your pull request: Overall ReviewThis pull request effectively addresses a critical crash scenario by reordering the cancellation check within the Detailed Review
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request addresses a critical crash that occurs when a request is cancelled. The fix correctly prioritizes checking for request cancellation before attempting to process any associated error, which could be malformed and cause a runtime error. The change is logical, well-contained, and is accompanied by a specific test case that validates the fix by simulating the exact crash scenario. The implementation is sound and effectively resolves the reported issue.
…requests to prevent crash (google-gemini#6039)
#6039) Co-authored-by: Jacob Richman <jacob314@gmail.com>
…h (#6039) Co-authored-by: Jacob Richman <jacob314@gmail.com>
google-gemini#6039) Co-authored-by: Jacob Richman <jacob314@gmail.com>
google-gemini#6039) Co-authored-by: Jacob Richman <jacob314@gmail.com>

TLDR
Fix crash caused by accessing error properties on cancelled requests.
Checks for request cancellation early and gracefully handles it to prevent runtime errors.
Dive Deeper
When a user cancels a request (e.g., by pressing ESC), the error handling code attempts to read properties from an undefined error object, causing a crash.
This change moves the cancellation check before any error processing, so if the request is aborted, the code emits a cancellation event and exits cleanly without throwing exceptions or processing undefined errors.
Reviewer Test Plan
Send requests and cancel them using ESC abort signals.
Verify that no unnecessary exception handling occurs upon cancellation.
Verify that the UserCancelled event is emitted appropriately on cancellation.
Ensure that normal errors (e.g., UnauthorizedError) are still handled correctly.
Testing Matrix
Linked issues / bugs
Fixes #5935