Skip to content

Commit

Permalink
net: use ERR_INVALID_ARG_VALUE instead of ERR_INVALID_OPT_VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
yanivfriedensohn authored and Trott committed Aug 22, 2018
1 parent 7be75d8 commit 630d987
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 5 additions & 7 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const errors = require('internal/errors');
const {
ERR_INVALID_ADDRESS_FAMILY,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INVALID_FD_TYPE,
ERR_INVALID_IP_ADDRESS,
ERR_INVALID_OPT_VALUE,
Expand Down Expand Up @@ -1496,15 +1497,12 @@ Server.prototype.listen = function(...args) {
return this;
}

let additionalMessage;
if (typeof options === 'object' &&
!(('port' in options) || ('path' in options))) {

additionalMessage = '"port" or "path" must be specified in options.';
if (!(('port' in options) || ('path' in options))) {
throw new ERR_INVALID_ARG_VALUE('options', options,
'must have the property "port" or "path"');
}

throw new ERR_INVALID_OPT_VALUE('options', util.inspect(options),
additionalMessage);
throw new ERR_INVALID_OPT_VALUE('options', util.inspect(options));
};

function lookupAndListen(self, port, address, backlog, exclusive) {
Expand Down
22 changes: 16 additions & 6 deletions test/parallel/test-net-server-listen-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ const listenOnPort = [
net.createServer().listen(options, common.mustNotCall());
};

common.expectsError(block,
{
code: 'ERR_INVALID_OPT_VALUE',
type: TypeError,
message: /^The value "{.*}" is invalid for option "options"(?:\. .+)?$/,
});
if (typeof options === 'object' &&
!(('port' in options) || ('path' in options))) {
common.expectsError(block,
{
code: 'ERR_INVALID_ARG_VALUE',
type: TypeError,
message: /^The argument 'options' must have the property "port" or "path"\. Received .+$/,
});
} else {
common.expectsError(block,
{
code: 'ERR_INVALID_OPT_VALUE',
type: TypeError,
message: /^The value "{.*}" is invalid for option "options"(?:\. .+)?$/,
});
}
}

shouldFailToListen(false, { port: false });
Expand Down

0 comments on commit 630d987

Please sign in to comment.