Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ process.on('uncaughtException', (error) => {
const isPtyResizeError =
error.message === 'Cannot resize a pty that has already exited';
const isEbadfError = error.message.includes('EBADF');
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');
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');
Comment on lines 32 to +37
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

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.

Suggested change
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
  1. When consuming an object, if a property is optional in its type definition (interface), callers must handle the undefined case (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.


if (
(isPtyResizeError || isEbadfError || isIoctlError || isEsrchError) &&
isFromNodePty
) {
// This error happens with node-pty when resizing a pty that has just exited.
// It is a race condition in node-pty that we cannot prevent, so we silence it.
return;
Expand Down