Skip to content

Commit ec4c256

Browse files
aduh95guangwong
authored andcommitted
tty: fix TypeError when stream is closed
Fixes: nodejs/node#41330 PR-URL: nodejs/node#43803 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 10939d7 commit ec4c256

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/tty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ObjectSetPrototypeOf(ReadStream, net.Socket);
7373

7474
ReadStream.prototype.setRawMode = function(flag) {
7575
flag = !!flag;
76-
const err = this._handle.setRawMode(flag);
76+
const err = this._handle?.setRawMode(flag);
7777
if (err) {
7878
this.emit('error', errors.errnoException(err, 'setRawMode'));
7979
return this;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (!process.stdin.isTTY) {
5+
common.skip('does not apply on non-TTY stdin');
6+
}
7+
8+
process.stdin.destroy();
9+
process.stdin.setRawMode(true);

0 commit comments

Comments
 (0)