This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tty: throw an Error when getWindowSize() fails
- Loading branch information
1 parent
4e48605
commit f1f5de1
Showing
1 changed file
with
16 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Member
|
||
} | ||
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; | ||
} |
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.