Skip to content

Commit 9e6812f

Browse files
committed
tty: fix TypeError when stream is closed
Fixes: nodejs#41330
1 parent 7f7a899 commit 9e6812f

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
@@ -72,7 +72,7 @@ ObjectSetPrototypeOf(ReadStream, net.Socket);
7272

7373
ReadStream.prototype.setRawMode = function(flag) {
7474
flag = !!flag;
75-
const err = this._handle.setRawMode(flag);
75+
const err = this._handle?.setRawMode(flag);
7676
if (err) {
7777
this.emit('error', errors.errnoException(err, 'setRawMode'));
7878
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)