Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
santigimeno committed Dec 26, 2022
1 parent 7b7db3b commit 1aa5e97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions doc/api/errors.md
Expand Up @@ -2573,6 +2573,13 @@ could not be determined.

An attempt was made to operate on an already closed socket.

<a id="ERR_SOCKET_CLOSED_BEFORE_CONNECTION"></a>

### `ERR_SOCKET_CLOSED_BEFORE_CONNECTION`

When calling [`net.Socket.write()`][] on a connecting socket and the socket was
closed before the connection was established.

<a id="ERR_SOCKET_DGRAM_IS_CONNECTED"></a>

### `ERR_SOCKET_DGRAM_IS_CONNECTED`
Expand Down Expand Up @@ -3586,6 +3593,7 @@ The native call from `process.cpuUsage` could not be processed.
[`http`]: http.md
[`https`]: https.md
[`libuv Error handling`]: https://docs.libuv.org/en/v1.x/errors.html
[`net.Socket.write()`]: net.md#socketwritedata-encoding-callback
[`net`]: net.md
[`new URL(input)`]: url.md#new-urlinput-base
[`new URLSearchParams(iterable)`]: url.md#new-urlsearchparamsiterable
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/errors.js
Expand Up @@ -1566,6 +1566,9 @@ E('ERR_SOCKET_BUFFER_SIZE',
'Could not get or set buffer size',
SystemError);
E('ERR_SOCKET_CLOSED', 'Socket is closed', Error);
E('ERR_SOCKET_CLOSED_BEFORE_CONNECTION',
'Socket was closed before connection established',
Error);
E('ERR_SOCKET_DGRAM_IS_CONNECTED', 'Already connected', Error);
E('ERR_SOCKET_DGRAM_NOT_CONNECTED', 'Not connected', Error);
E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running', Error);
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Expand Up @@ -98,6 +98,7 @@ const {
ERR_SERVER_ALREADY_LISTEN,
ERR_SERVER_NOT_RUNNING,
ERR_SOCKET_CLOSED,
ERR_SOCKET_CLOSED_BEFORE_CONNECTION,
ERR_MISSING_ARGS,
},
aggregateErrors,
Expand Down Expand Up @@ -900,7 +901,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
this._writeGeneric(writev, data, encoding, cb);
});
function onClose() {
cb(new ERR_SOCKET_CLOSED());
cb(new ERR_SOCKET_CLOSED_BEFORE_CONNECTION());
}
this.once('close', onClose);
return;
Expand Down
Expand Up @@ -8,14 +8,16 @@ const server = net.createServer();
server.listen(0, common.mustCall(() => {
const socket = new net.Socket();

socket.on('connect', common.mustNotCall());

socket.connect({
port: server.address().port,
});

assert(socket.connecting);

socket.write('foo', common.expectsError({
code: 'ERR_SOCKET_CLOSED',
code: 'ERR_SOCKET_CLOSED_BEFORE_CONNECTION',
name: 'Error'
}));

Expand Down

0 comments on commit 1aa5e97

Please sign in to comment.