From f1f5de1c8d289766ee1628a06cb7dbab440e12f8 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 30 Apr 2012 16:18:37 -0700 Subject: [PATCH] tty: throw an Error when getWindowSize() fails --- lib/tty.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/tty.js b/lib/tty.js index 8d90d0ecd0..72dd88d2bf 100644 --- a/lib/tty.js +++ b/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'); + } 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; +}