fix(cli): harden uncaughtException handler for PTY resize errors#27525
fix(cli): harden uncaughtException handler for PTY resize errors#27525amitesh0303 wants to merge 1 commit into
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. |
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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'); |
There was a problem hiding this comment.
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.
| 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
- 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 ??).
Summary
Details
Related Issues
How to Validate
Pre-Merge Checklist