diff --git a/lib/dgram.js b/lib/dgram.js index 4d5ea7c3b2afbc..cc2d11b81ecfa6 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -173,11 +173,13 @@ function bufferSize(self, size, buffer) { if (size >>> 0 !== size) throw new errors.TypeError('ERR_SOCKET_BAD_BUFFER_SIZE'); - try { - return self._handle.bufferSize(size, buffer); - } catch (e) { - throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e); + const ctx = {}; + const ret = self._handle.bufferSize(size, buffer, ctx); + if (ret === undefined) { + throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', + new errors.SystemError(ctx)); } + return ret; } Socket.prototype.bind = function(port_, address_ /*, callback*/) { diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index b3702ea6e3feb2..05682a3e1f4753 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -234,8 +234,10 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo& args) { const char* uv_func_name = is_recv ? "uv_recv_buffer_size" : "uv_send_buffer_size"; - if (!args[0]->IsInt32()) - return env->ThrowUVException(UV_EINVAL, uv_func_name); + if (!args[0]->IsInt32()) { + env->CollectUVExceptionInfo(args[2], UV_EINVAL, uv_func_name); + return args.GetReturnValue().SetUndefined(); + } uv_handle_t* handle = reinterpret_cast(&wrap->handle_); int size = static_cast(args[0].As()->Value()); @@ -246,8 +248,10 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo& args) { else err = uv_send_buffer_size(handle, &size); - if (err != 0) - return env->ThrowUVException(err, uv_func_name); + if (err != 0) { + env->CollectUVExceptionInfo(args[2], err, uv_func_name); + return args.GetReturnValue().SetUndefined(); + } args.GetReturnValue().Set(size); } diff --git a/test/parallel/test-dgram-socket-buffer-size.js b/test/parallel/test-dgram-socket-buffer-size.js index 7d6e2bfcc564ca..2ef09f98fe13a6 100644 --- a/test/parallel/test-dgram-socket-buffer-size.js +++ b/test/parallel/test-dgram-socket-buffer-size.js @@ -77,8 +77,7 @@ 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` + message: /^Could not get or set buffer size:.*$/ }; const functionName = `set${type.charAt(0).toUpperCase()}${type.slice(1)}` + 'BufferSize';