mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
net: migrate errors to internal/errors
Throw ERR_SOCKET_CLOSED and ERR_SERVER_NOT_RUNNING instead of the old-style errors in net.js. PR-URL: https://github.com/nodejs/node/pull/17766 Refs: https://github.com/nodejs/node/issues/17709 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
8599465d33
commit
b98aaa312e
6 files changed
+31
-13
No files matched your search
@@ -58,8 +58,10 @@ server.listen(common.PIPE, common.mustCall(function() {
|
||||
assert.strictEqual(res.body, 'hello world\n');
|
||||
server.close(common.mustCall(function(error) {
|
||||
assert.strictEqual(error, undefined);
|
||||
server.close(common.mustCall(function(error) {
|
||||
assert.strictEqual(error && error.message, 'Not running');
|
||||
server.close(common.expectsError({
|
||||
code: 'ERR_SERVER_NOT_RUNNING',
|
||||
message: 'Server is not running.',
|
||||
type: Error
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
|
||||
@@ -12,11 +12,16 @@ server.listen(0, common.mustCall(function() {
|
||||
conn.on('connect', common.mustCall(function() {
|
||||
// Test destroy returns this, even on multiple calls when it short-circuits.
|
||||
assert.strictEqual(conn, conn.destroy().destroy());
|
||||
conn.on('error', common.mustCall(function(err) {
|
||||
assert.strictEqual(err.message, 'This socket is closed');
|
||||
conn.on('error', common.expectsError({
|
||||
code: 'ERR_SOCKET_CLOSED',
|
||||
message: 'Socket is closed',
|
||||
type: Error
|
||||
}));
|
||||
conn.write(Buffer.from('kaboom'), common.mustCall(function(err) {
|
||||
assert.strictEqual(err.message, 'This socket is closed');
|
||||
|
||||
conn.write(Buffer.from('kaboom'), common.expectsError({
|
||||
code: 'ERR_SOCKET_CLOSED',
|
||||
message: 'Socket is closed',
|
||||
type: Error
|
||||
}));
|
||||
server.close();
|
||||
}));
|
||||
|
||||
@@ -26,11 +26,14 @@ const net = require('net');
|
||||
server.listen(common.mustCall(() => {
|
||||
const port = server.address().port;
|
||||
const client = net.connect({ port }, common.mustCall(() => {
|
||||
client.on('error', common.mustCall((err) => {
|
||||
server.close();
|
||||
assert.strictEqual(err.constructor, Error);
|
||||
assert.strictEqual(err.message, 'This socket is closed');
|
||||
client.on('error', common.expectsError({
|
||||
code: 'ERR_SOCKET_CLOSED',
|
||||
message: 'Socket is closed',
|
||||
type: Error
|
||||
}));
|
||||
|
||||
server.close();
|
||||
|
||||
client._handle.close();
|
||||
client._handle = null;
|
||||
client.write('foo');
|
||||
|
||||
Reference in new issue
Block a user