Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
tty: throw an Error when getWindowSize() fails
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Apr 30, 2012
1 parent 4e48605 commit f1f5de1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/tty.js
Expand Up @@ -84,8 +84,10 @@ function WriteStream(fd) {
this.writable = true;

var winSize = this._handle.getWindowSize();
this.columns = winSize[0];
this.rows = winSize[1];
if (winSize) {
this.columns = winSize[0];
this.rows = winSize[1];
}
}
inherits(WriteStream, net.Socket);
exports.WriteStream = WriteStream;
Expand All @@ -98,6 +100,9 @@ WriteStream.prototype._refreshSize = function() {
var oldCols = this.columns;
var oldRows = this.rows;
var winSize = this._handle.getWindowSize();
if (!winSize) {
throw errnoException(errno, 'getWindowSize');

This comment has been minimized.

Copy link
@isaacs

isaacs May 1, 2012

Throwing is excessive here. Yes, it's rare, but I think a stray SIGWINCH is not a major enough issue to crash a server. Emit an error instead.

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis May 1, 2012

Member

It looks right to me. Node hooks up the SIGWINCH handler if (and only if) stdout is a TTY. .getWindowSize() calls ioctl(TIOCGWINSZ). If the ioctl fails, it means a basic assumption about the environment is wrong (stdout is not a TTY, someone or something already closed stdout, etc.). In other words, there is a bug somewhere.

}
var newCols = winSize[0];
var newRows = winSize[1];
if (oldCols !== newCols || oldRows !== newRows) {
Expand All @@ -124,3 +129,12 @@ WriteStream.prototype.clearScreenDown = function() {
WriteStream.prototype.getWindowSize = function() {
return [this.columns, this.rows];
};


// TODO share with net_uv and others
function errnoException(errorno, syscall) {
var e = new Error(syscall + ' ' + errorno);
e.errno = e.code = errorno;
e.syscall = syscall;
return e;
}

0 comments on commit f1f5de1

Please sign in to comment.