From 20167fe6107b2240f5110a0d9363fe45e38a95d3 Mon Sep 17 00:00:00 2001 From: Bougarfaoui El houcine Date: Mon, 13 Feb 2017 16:03:35 -0500 Subject: [PATCH 1/3] errors: migrate socket_list to internal/errors --- lib/internal/errors.js | 1 + lib/internal/socket_list.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 31c8fa945aeb64..0b1b13388df965 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -177,6 +177,7 @@ E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type'); E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + 'See https://github.com/nodejs/node/wiki/Intl'); // Add new errors from here... +E('ERR_SLAVE_CLOSED_BEFORE_REPLY','Slave closed before reply'); function invalidArgType(name, expected, actual) { assert(name, 'name is required'); diff --git a/lib/internal/socket_list.js b/lib/internal/socket_list.js index 15e880ba8c13d4..b367649ba0c8b9 100644 --- a/lib/internal/socket_list.js +++ b/lib/internal/socket_list.js @@ -1,5 +1,7 @@ 'use strict'; +const errors = require('internal/errors'); + const EventEmitter = require('events'); // This object keeps track of the sockets that are sent @@ -18,7 +20,7 @@ class SocketListSend extends EventEmitter { function onclose() { self.child.removeListener('internalMessage', onreply); - callback(new Error('child closed before reply')); + callback(new errors.Error('ERR_SLAVE_CLOSED_BEFORE_REPLY')); } function onreply(msg) { From 71cb15378cc3d93ef6217a7e0066c58d4a7c9af2 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Wed, 19 Jul 2017 17:57:35 -0400 Subject: [PATCH 2/3] [fixup] --- doc/api/errors.md | 5 +++++ lib/internal/errors.js | 4 ++-- lib/internal/socket_list.js | 2 +- .../test-internal-socket-list-send.js | 22 ++++++++++++++----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 5127b9f571acc0..8526f190f516cc 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -580,6 +580,11 @@ by the `assert` module. Used when attempting to perform an operation outside the bounds of a `Buffer`. + +### ERR_CHILD_CLOSED_BEFORE_REPLY + +Used when a child process is closed before the parent got a replay. + ### ERR_CONSOLE_WRITABLE_STREAM diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 0b1b13388df965..1634a09a893c56 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -102,6 +102,7 @@ module.exports = exports = { E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); E('ERR_ASSERTION', '%s'); E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds); +E('ERR_CHILD_CLOSED_BEFORE_REPLY','Child closed before reply received'); E('ERR_CONSOLE_WRITABLE_STREAM', 'Console expects a writable stream instance for %s'); E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s'); @@ -176,8 +177,7 @@ E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type'); E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type'); E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + 'See https://github.com/nodejs/node/wiki/Intl'); -// Add new errors from here... -E('ERR_SLAVE_CLOSED_BEFORE_REPLY','Slave closed before reply'); + function invalidArgType(name, expected, actual) { assert(name, 'name is required'); diff --git a/lib/internal/socket_list.js b/lib/internal/socket_list.js index b367649ba0c8b9..f6091c0c66055d 100644 --- a/lib/internal/socket_list.js +++ b/lib/internal/socket_list.js @@ -20,7 +20,7 @@ class SocketListSend extends EventEmitter { function onclose() { self.child.removeListener('internalMessage', onreply); - callback(new errors.Error('ERR_SLAVE_CLOSED_BEFORE_REPLY')); + callback(new errors.Error('ERR_CHILD_CLOSED_BEFORE_REPLY')); } function onreply(msg) { diff --git a/test/parallel/test-internal-socket-list-send.js b/test/parallel/test-internal-socket-list-send.js index 10413bfdbcb839..797baf43f4dd76 100644 --- a/test/parallel/test-internal-socket-list-send.js +++ b/test/parallel/test-internal-socket-list-send.js @@ -17,7 +17,11 @@ const key = 'test-key'; const list = new SocketListSend(child, 'test'); list._request('msg', 'cmd', common.mustCall((err) => { - assert.strictEqual(err.message, 'child closed before reply'); + common.expectsError({ + code: 'ERR_CHILD_CLOSED_BEFORE_REPLY', + type: Error, + message: 'Child closed before reply received' + })(err); assert.strictEqual(child.listenerCount('internalMessage'), 0); })); } @@ -55,7 +59,11 @@ const key = 'test-key'; const list = new SocketListSend(child, key); list._request('msg', 'cmd', common.mustCall((err) => { - assert.strictEqual(err.message, 'child closed before reply'); + common.expectsError({ + code: 'ERR_CHILD_CLOSED_BEFORE_REPLY', + type: Error, + message: 'Child closed before reply received' + })(err); assert.strictEqual(child.listenerCount('internalMessage'), 0); })); } @@ -119,7 +127,7 @@ const key = 'test-key'; const count = 1; const child = Object.assign(new EventEmitter(), { connected: true, - send: function(msg) { + send: function() { process.nextTick(() => { this.emit('disconnect'); this.emit('internalMessage', { key, count, cmd: 'NODE_SOCKET_COUNT' }); @@ -129,8 +137,12 @@ const key = 'test-key'; const list = new SocketListSend(child, key); - list.getConnections(common.mustCall((err, msg) => { - assert.strictEqual(err.message, 'child closed before reply'); + list.getConnections(common.mustCall((err) => { + common.expectsError({ + code: 'ERR_CHILD_CLOSED_BEFORE_REPLY', + type: Error, + message: 'Child closed before reply received' + })(err); assert.strictEqual(child.listenerCount('internalMessage'), 0); })); } From 10bf0e12c8e389c9315323fa929a1e0360ccb672 Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Fri, 21 Jul 2017 06:07:47 -0400 Subject: [PATCH 3/3] typos --- doc/api/errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 8526f190f516cc..2d4f3f02e94e79 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -583,7 +583,7 @@ Used when attempting to perform an operation outside the bounds of a `Buffer`. ### ERR_CHILD_CLOSED_BEFORE_REPLY -Used when a child process is closed before the parent got a replay. +Used when a child process is closed before the parent received a reply. ### ERR_CONSOLE_WRITABLE_STREAM