errors: migrate socket_list to internal/errors

PR-URL: https://github.com/nodejs/node/pull/11356
Refs: https://github.com/nodejs/node/issues/11273
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Bougarfaoui El houcine 2017-02-13 16:03:35 -05:00 committed by Refael Ackermann
parent d8eb30ac10
commit a03d8cee1f
No known key found for this signature in database
GPG Key ID: CD704BD80FDDDB64
4 changed files with 27 additions and 7 deletions

View File

@ -580,6 +580,11 @@ by the `assert` module.
Used when attempting to perform an operation outside the bounds of a `Buffer`. Used when attempting to perform an operation outside the bounds of a `Buffer`.
<a id="ERR_CHILD_CLOSED_BEFORE_REPLY"></a>
### ERR_CHILD_CLOSED_BEFORE_REPLY
Used when a child process is closed before the parent received a reply.
<a id="ERR_CONSOLE_WRITABLE_STREAM"></a> <a id="ERR_CONSOLE_WRITABLE_STREAM"></a>
### ERR_CONSOLE_WRITABLE_STREAM ### ERR_CONSOLE_WRITABLE_STREAM

View File

@ -102,6 +102,7 @@ module.exports = exports = {
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); E('ERR_ARG_NOT_ITERABLE', '%s must be iterable');
E('ERR_ASSERTION', '%s'); E('ERR_ASSERTION', '%s');
E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds); E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds);
E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received');
E('ERR_CONSOLE_WRITABLE_STREAM', E('ERR_CONSOLE_WRITABLE_STREAM',
'Console expects a writable stream instance for %s'); 'Console expects a writable stream instance for %s');
E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s'); E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s');
@ -183,7 +184,7 @@ E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type');
E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type'); E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type');
E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' +
'See https://github.com/nodejs/node/wiki/Intl'); 'See https://github.com/nodejs/node/wiki/Intl');
// Add new errors from here...
function invalidArgType(name, expected, actual) { function invalidArgType(name, expected, actual) {
assert(name, 'name is required'); assert(name, 'name is required');

View File

@ -1,5 +1,7 @@
'use strict'; 'use strict';
const errors = require('internal/errors');
const EventEmitter = require('events'); const EventEmitter = require('events');
// This object keeps track of the sockets that are sent // This object keeps track of the sockets that are sent
@ -18,7 +20,7 @@ class SocketListSend extends EventEmitter {
function onclose() { function onclose() {
self.child.removeListener('internalMessage', onreply); self.child.removeListener('internalMessage', onreply);
callback(new Error('child closed before reply')); callback(new errors.Error('ERR_CHILD_CLOSED_BEFORE_REPLY'));
} }
function onreply(msg) { function onreply(msg) {

View File

@ -17,7 +17,11 @@ const key = 'test-key';
const list = new SocketListSend(child, 'test'); const list = new SocketListSend(child, 'test');
list._request('msg', 'cmd', common.mustCall((err) => { 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); assert.strictEqual(child.listenerCount('internalMessage'), 0);
})); }));
} }
@ -55,7 +59,11 @@ const key = 'test-key';
const list = new SocketListSend(child, key); const list = new SocketListSend(child, key);
list._request('msg', 'cmd', common.mustCall((err) => { 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); assert.strictEqual(child.listenerCount('internalMessage'), 0);
})); }));
} }
@ -119,7 +127,7 @@ const key = 'test-key';
const count = 1; const count = 1;
const child = Object.assign(new EventEmitter(), { const child = Object.assign(new EventEmitter(), {
connected: true, connected: true,
send: function(msg) { send: function() {
process.nextTick(() => { process.nextTick(() => {
this.emit('disconnect'); this.emit('disconnect');
this.emit('internalMessage', { key, count, cmd: 'NODE_SOCKET_COUNT' }); this.emit('internalMessage', { key, count, cmd: 'NODE_SOCKET_COUNT' });
@ -129,8 +137,12 @@ const key = 'test-key';
const list = new SocketListSend(child, key); const list = new SocketListSend(child, key);
list.getConnections(common.mustCall((err, msg) => { list.getConnections(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); assert.strictEqual(child.listenerCount('internalMessage'), 0);
})); }));
} }