summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhillip Johnsen <johphi@gmail.com>2016-03-31 22:44:02 +0200
committerJames M Snell <jasnell@gmail.com>2016-04-01 09:46:01 -0700
commitec49fc822901e1a0deb510a876485f5e94b72866 (patch)
treec2d34c5b6b7ae691ba269c35e6621bc273abd317 /test
parent8dcb82db38e4dd7e8748622fb2494a0571d85f28 (diff)
downloadandroid-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 'test')
-rw-r--r--test/parallel/test-net-socket-write-error.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/parallel/test-net-socket-write-error.js b/test/parallel/test-net-socket-write-error.js
new file mode 100644
index 0000000000..db236be1a5
--- /dev/null
+++ b/test/parallel/test-net-socket-write-error.js
@@ -0,0 +1,18 @@
+'use strict';
+
+const common = require('../common');
+const assert = require('assert');
+const net = require('net');
+
+const server = net.createServer().listen(common.PORT, connectToServer);
+
+function connectToServer() {
+ const client = net.createConnection(common.PORT, () => {
+ assert.throws(() => {
+ client.write(1337);
+ }, /Invalid data, chunk must be a string or buffer, not number/);
+
+ client.end();
+ })
+ .on('end', () => server.close());
+}