Skip to content

fix(cli): harden uncaughtException handler for PTY resize errors#27525

Open
amitesh0303 wants to merge 1 commit into
google-gemini:mainfrom
amitesh0303:fix/uncaught-exception-handler
Open

fix(cli): harden uncaughtException handler for PTY resize errors#27525
amitesh0303 wants to merge 1 commit into
google-gemini:mainfrom
amitesh0303:fix/uncaught-exception-handler

Conversation

@amitesh0303
Copy link
Copy Markdown

Summary

Details

Related Issues

How to Validate

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@amitesh0303 amitesh0303 requested a review from a team as a code owner May 28, 2026 11:52
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 28, 2026

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 strengthens the CLI's resilience by updating the uncaughtException handler to better manage race conditions inherent in PTY resizing. By broadening the scope of captured error types and improving the identification of PTY-related stack traces, the change ensures that transient errors from the underlying terminal emulation layer do not cause the application to terminate unexpectedly.

Highlights

  • Improved Error Handling: Added detection for 'ioctl(2) failed' and 'ESRCH' error messages to the uncaughtException handler to prevent crashes during PTY resizing.
  • Enhanced Stack Trace Detection: Expanded the 'isFromNodePty' logic to include additional patterns such as 'UnixTerminal.resize', 'WindowsTerminal.resize', and 'resizePty' for more reliable error identification.
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 the 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 counterproductive. 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.

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
Copy Markdown
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 updates the global uncaughtException handler in packages/cli/index.ts to silence additional node-pty related errors, specifically checking for ioctl(2) failed and ESRCH errors, and expanding the stack trace checks. The reviewer recommends using optional chaining (error.message?.includes(...)) defensively to prevent a potential TypeError if error.message is undefined, which would crash the global exception handler.

Comment thread packages/cli/index.ts
Comment on lines +27 to +31
const isIoctlError = error.message.includes('ioctl(2) failed');
const isEsrchError =
error.message.includes('ESRCH') ||
(typeof (error as { code?: string }).code === 'string' &&
(error as { code?: string }).code === 'ESRCH');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

In JavaScript/TypeScript, error.message can occasionally be undefined or not a string (e.g., in custom or poorly constructed errors). Calling .includes() directly on it can throw a TypeError, which would crash the global uncaughtException handler itself and prevent the fallback logging and graceful exit logic from running. Use optional chaining (error.message?.includes(...)) and provide a fallback value to handle this defensively.

Suggested change
const isIoctlError = error.message.includes('ioctl(2) failed');
const isEsrchError =
error.message.includes('ESRCH') ||
(typeof (error as { code?: string }).code === 'string' &&
(error as { code?: string }).code === 'ESRCH');
const isIoctlError = error.message?.includes('ioctl(2) failed') ?? false;
const isEsrchError =
(error.message?.includes('ESRCH') ?? false) ||
(typeof (error as { code?: string }).code === 'string' &&
(error as { code?: string }).code === 'ESRCH');
References
  1. When consuming an object, if a property is optional in its type definition, callers must handle the undefined case (e.g., by providing a default with ??).

@gemini-cli gemini-cli Bot added the priority/p1 Important and should be addressed in the near term. label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants