mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 06:38:13 +00:00

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>
19 lines
460 B
JavaScript
19 lines
460 B
JavaScript
'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());
|
|
}
|