From c6aaaf003fdd9951210d48515afe7fc10f8df783 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sun, 17 Sep 2017 12:11:51 +0200 Subject: [PATCH] src: use UV_EINVAL instead of EINVAL in udp_wrap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently if the buffer size exceeds the maximum int size the following error will be thrown: dgram.js:180 throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e); ^ Error [ERR_SOCKET_BUFFER_SIZE]: Could not get or set buffer size: Error: Unknown system error 22: Unknown system error 22, uv_recv_buffer_size at bufferSize (dgram.js:180:11) It looks like perhaps UV_EINVAL was intended to give the following error message instead: dgram.js:180 throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e); ^ Error [ERR_SOCKET_BUFFER_SIZE]: Could not get or set buffer size: Error: EINVAL: invalid argument, uv_recv_buffer_size at bufferSize (dgram.js:180:11) This commit changes EINVAL to use UV_EINVAL. PR-URL: https://github.com/nodejs/node/pull/15444 Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/udp_wrap.cc | 4 ++-- .../parallel/test-dgram-socket-buffer-size.js | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 92834d4b0ea0d4..f4eb29ccf471d7 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -237,9 +237,9 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo& args) { if (!args[0]->IsInt32()) { if (args[1].As()->Value() == 0) - return env->ThrowUVException(EINVAL, "uv_recv_buffer_size"); + return env->ThrowUVException(UV_EINVAL, "uv_recv_buffer_size"); else - return env->ThrowUVException(EINVAL, "uv_send_buffer_size"); + return env->ThrowUVException(UV_EINVAL, "uv_send_buffer_size"); } int err; diff --git a/test/parallel/test-dgram-socket-buffer-size.js b/test/parallel/test-dgram-socket-buffer-size.js index 13fbd4fb4be601..7d6e2bfcc564ca 100644 --- a/test/parallel/test-dgram-socket-buffer-size.js +++ b/test/parallel/test-dgram-socket-buffer-size.js @@ -72,3 +72,24 @@ const dgram = require('dgram'); socket.close(); })); } + +function checkBufferSizeError(type, size) { + const errorObj = { + code: 'ERR_SOCKET_BUFFER_SIZE', + type: Error, + message: 'Could not get or set buffer size: Error: EINVAL: ' + + `invalid argument, uv_${type}_buffer_size` + }; + const functionName = `set${type.charAt(0).toUpperCase()}${type.slice(1)}` + + 'BufferSize'; + const socket = dgram.createSocket('udp4'); + socket.bind(common.mustCall(() => { + assert.throws(() => { + socket[functionName](size); + }, common.expectsError(errorObj)); + socket.close(); + })); +} + +checkBufferSizeError('recv', 2147483648); +checkBufferSizeError('send', 2147483648);