Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

tty: throw an Error when getWindowSize() fails

  • Loading branch information
TooTallNate committed Apr 30, 2012
1 parent 4e48605 commit f1f5de1c8d289766ee1628a06cb7dbab440e12f8
Showing with 16 additions and 2 deletions.
  1. +16 −2 lib/tty.js
@@ -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;
@@ -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) {
@@ -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.
You can’t perform that action at this time.