Skip to content

Commit a03d8ce

Browse files
Bougarfaoui El houcinerefack
Bougarfaoui El houcine
authored andcommitted
errors: migrate socket_list to internal/errors
PR-URL: #11356 Refs: #11273 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent d8eb30a commit a03d8ce

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

doc/api/errors.md

+5
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ by the `assert` module.
580580

581581
Used when attempting to perform an operation outside the bounds of a `Buffer`.
582582

583+
<a id="ERR_CHILD_CLOSED_BEFORE_REPLY"></a>
584+
### ERR_CHILD_CLOSED_BEFORE_REPLY
585+
586+
Used when a child process is closed before the parent received a reply.
587+
583588
<a id="ERR_CONSOLE_WRITABLE_STREAM"></a>
584589
### ERR_CONSOLE_WRITABLE_STREAM
585590

lib/internal/errors.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ module.exports = exports = {
102102
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable');
103103
E('ERR_ASSERTION', '%s');
104104
E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds);
105+
E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received');
105106
E('ERR_CONSOLE_WRITABLE_STREAM',
106107
'Console expects a writable stream instance for %s');
107108
E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s');
@@ -183,7 +184,7 @@ E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
183184
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
184185
E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
185186
'See https://github.com/nodejs/node/wiki/Intl');
186-
// Add new errors from here...
187+
187188

188189
function invalidArgType(name, expected, actual) {
189190
assert(name, 'name is required');

lib/internal/socket_list.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const errors = require('internal/errors');
4+
35
const EventEmitter = require('events');
46

57
// This object keeps track of the sockets that are sent
@@ -18,7 +20,7 @@ class SocketListSend extends EventEmitter {
1820

1921
function onclose() {
2022
self.child.removeListener('internalMessage', onreply);
21-
callback(new Error('child closed before reply'));
23+
callback(new errors.Error('ERR_CHILD_CLOSED_BEFORE_REPLY'));
2224
}
2325

2426
function onreply(msg) {

test/parallel/test-internal-socket-list-send.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ const key = 'test-key';
1717
const list = new SocketListSend(child, 'test');
1818

1919
list._request('msg', 'cmd', common.mustCall((err) => {
20-
assert.strictEqual(err.message, 'child closed before reply');
20+
common.expectsError({
21+
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
22+
type: Error,
23+
message: 'Child closed before reply received'
24+
})(err);
2125
assert.strictEqual(child.listenerCount('internalMessage'), 0);
2226
}));
2327
}
@@ -55,7 +59,11 @@ const key = 'test-key';
5559
const list = new SocketListSend(child, key);
5660

5761
list._request('msg', 'cmd', common.mustCall((err) => {
58-
assert.strictEqual(err.message, 'child closed before reply');
62+
common.expectsError({
63+
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
64+
type: Error,
65+
message: 'Child closed before reply received'
66+
})(err);
5967
assert.strictEqual(child.listenerCount('internalMessage'), 0);
6068
}));
6169
}
@@ -119,7 +127,7 @@ const key = 'test-key';
119127
const count = 1;
120128
const child = Object.assign(new EventEmitter(), {
121129
connected: true,
122-
send: function(msg) {
130+
send: function() {
123131
process.nextTick(() => {
124132
this.emit('disconnect');
125133
this.emit('internalMessage', { key, count, cmd: 'NODE_SOCKET_COUNT' });
@@ -129,8 +137,12 @@ const key = 'test-key';
129137

130138
const list = new SocketListSend(child, key);
131139

132-
list.getConnections(common.mustCall((err, msg) => {
133-
assert.strictEqual(err.message, 'child closed before reply');
140+
list.getConnections(common.mustCall((err) => {
141+
common.expectsError({
142+
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
143+
type: Error,
144+
message: 'Child closed before reply received'
145+
})(err);
134146
assert.strictEqual(child.listenerCount('internalMessage'), 0);
135147
}));
136148
}

0 commit comments

Comments
 (0)