diff options
author | rickyes <mail@zhoumq.cn> | 2020-04-15 08:23:26 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-04-28 20:15:03 +0300 |
commit | 1d0b24924f0953d022167df90c018a75139c71a4 (patch) | |
tree | efff45fed4f617f22e9e9ddefe5c52a7b1d89230 /lib/internal/errors.js | |
parent | aa9708e479787bdffc9e837a6599f10581014891 (diff) |
lib: fix validateport error message when allowZero is false
PR-URL: https://github.com/nodejs/node/pull/32861
Fixes: https://github.com/nodejs/node/issues/32857
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/internal/errors.js')
-rw-r--r-- | lib/internal/errors.js | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 3f31bdc330d..2a162f14b24 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1318,8 +1318,12 @@ E('ERR_SERVER_NOT_RUNNING', 'Server is not running.', Error); E('ERR_SOCKET_ALREADY_BOUND', 'Socket is already bound', Error); E('ERR_SOCKET_BAD_BUFFER_SIZE', 'Buffer size must be a positive integer', TypeError); -E('ERR_SOCKET_BAD_PORT', - '%s should be >= 0 and < 65536. Received %s.', RangeError); +E('ERR_SOCKET_BAD_PORT', (name, port, allowZero = true) => { + assert(typeof allowZero === 'boolean', + "The 'allowZero' argument must be of type boolean."); + const operator = allowZero ? '>=' : '>'; + return `${name} should be ${operator} 0 and < 65536. Received ${port}.`; +}, RangeError); E('ERR_SOCKET_BAD_TYPE', 'Bad socket type specified. Valid types are: udp4, udp6', TypeError); E('ERR_SOCKET_BUFFER_SIZE', |