mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 11:12:55 +00:00

Logic errors that do not depend on stream state should throw instead of invoke callback and emit error. PR-URL: https://github.com/nodejs/node/pull/31831 Refs: https://github.com/nodejs/node/pull/31818 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
23 lines
517 B
JavaScript
23 lines
517 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const net = require('net');
|
|
const assert = require('assert');
|
|
|
|
const server = net.createServer().listen(0, connectToServer);
|
|
|
|
function connectToServer() {
|
|
const client = net.createConnection(this.address().port, () => {
|
|
client.on('error', common.mustNotCall());
|
|
assert.throws(() => {
|
|
client.write(1337);
|
|
}, {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
name: 'TypeError'
|
|
});
|
|
|
|
client.destroy();
|
|
})
|
|
.on('close', () => server.close());
|
|
}
|