fix(cli): harden uncaughtException handler for PTY resize errors#27526
fix(cli): harden uncaughtException handler for PTY resize errors#27526amitesh0303 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 enhances the stability of the CLI by hardening the uncaughtException handler. It specifically targets race conditions occurring during PTY resizing by silencing additional known error patterns that arise when a PTY process exits 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 expands the uncaught exception handler in the CLI package to silence additional expected errors from node-pty during PTY resizing, specifically handling ioctl(2) failed and ESRCH errors, and broadening the stack trace detection. The reviewer suggested explicitly handling the optional error.stack property by providing a default boolean value (?? false) to comply with TypeScript type safety guidelines instead of relying on implicit falsy coercion.
| const isFromNodePty = | ||
| error.stack?.includes('node-pty') || error.stack?.includes('PtyResize'); | ||
|
|
||
| if ((isPtyResizeError || isEbadfError) && isFromNodePty) { | ||
| error.stack?.includes('node-pty') || | ||
| error.stack?.includes('PtyResize') || | ||
| error.stack?.includes('UnixTerminal.resize') || | ||
| error.stack?.includes('WindowsTerminal.resize') || | ||
| error.stack?.includes('resizePty'); |
There was a problem hiding this comment.
The error.stack property is optional on the Error interface (its type is string | undefined). To comply with the repository guidelines, we must explicitly handle the undefined case by providing a default value (e.g., using ?? false) rather than relying on implicit falsy coercion in conditional checks.
| const isFromNodePty = | |
| error.stack?.includes('node-pty') || error.stack?.includes('PtyResize'); | |
| if ((isPtyResizeError || isEbadfError) && isFromNodePty) { | |
| error.stack?.includes('node-pty') || | |
| error.stack?.includes('PtyResize') || | |
| error.stack?.includes('UnixTerminal.resize') || | |
| error.stack?.includes('WindowsTerminal.resize') || | |
| error.stack?.includes('resizePty'); | |
| const isFromNodePty = | |
| (error.stack?.includes('node-pty') || | |
| error.stack?.includes('PtyResize') || | |
| error.stack?.includes('UnixTerminal.resize') || | |
| error.stack?.includes('WindowsTerminal.resize') || | |
| error.stack?.includes('resizePty')) ?? | |
| false; |
References
- When consuming an object, if a property is optional in its type definition (interface), callers must handle the
undefinedcase (e.g., by providing a default with??). Do not rely on the implementation details of the function that creates the object to always provide a value, as this can change. Code against the interface contract.
Summary
Details
Related Issues
How to Validate
Pre-Merge Checklist