diff options
author | Phillip Johnsen <johphi@gmail.com> | 2016-03-31 22:44:02 +0200 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-04-01 09:46:01 -0700 |
commit | ec49fc822901e1a0deb510a876485f5e94b72866 (patch) | |
tree | c2d34c5b6b7ae691ba269c35e6621bc273abd317 /lib | |
parent | 8dcb82db38e4dd7e8748622fb2494a0571d85f28 (diff) | |
download | android-node-v8-ec49fc822901e1a0deb510a876485f5e94b72866.tar.gz android-node-v8-ec49fc822901e1a0deb510a876485f5e94b72866.tar.bz2 android-node-v8-ec49fc822901e1a0deb510a876485f5e94b72866.zip |
net: improve socket.write() error message
Informative error messages are very important for developers and could
possibly save hours of debugging and frustration. This improves the error
message thrown when writing invalid data into a socket, by communicating
what's expected compared to what the developer just tried to write.
PR-URL: https://github.com/nodejs/node/pull/5981
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/net.js b/lib/net.js index dc96526683..09c582d9d7 100644 --- a/lib/net.js +++ b/lib/net.js @@ -619,8 +619,10 @@ Socket.prototype.__defineGetter__('localPort', function() { Socket.prototype.write = function(chunk, encoding, cb) { - if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) - throw new TypeError('Invalid data'); + if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) { + throw new TypeError( + 'Invalid data, chunk must be a string or buffer, not ' + typeof chunk); + } return stream.Duplex.prototype.write.apply(this, arguments); }; |