Skip to content

Commit f4899ac

Browse files
committed
src: use UV_EINVAL instead of EINVAL in udp_wrap
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: #15444 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3888a57 commit f4899ac

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/udp_wrap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
237237

238238
if (!args[0]->IsInt32()) {
239239
if (args[1].As<Uint32>()->Value() == 0)
240-
return env->ThrowUVException(EINVAL, "uv_recv_buffer_size");
240+
return env->ThrowUVException(UV_EINVAL, "uv_recv_buffer_size");
241241
else
242-
return env->ThrowUVException(EINVAL, "uv_send_buffer_size");
242+
return env->ThrowUVException(UV_EINVAL, "uv_send_buffer_size");
243243
}
244244

245245
int err;

test/parallel/test-dgram-socket-buffer-size.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,24 @@ const dgram = require('dgram');
7272
socket.close();
7373
}));
7474
}
75+
76+
function checkBufferSizeError(type, size) {
77+
const errorObj = {
78+
code: 'ERR_SOCKET_BUFFER_SIZE',
79+
type: Error,
80+
message: 'Could not get or set buffer size: Error: EINVAL: ' +
81+
`invalid argument, uv_${type}_buffer_size`
82+
};
83+
const functionName = `set${type.charAt(0).toUpperCase()}${type.slice(1)}` +
84+
'BufferSize';
85+
const socket = dgram.createSocket('udp4');
86+
socket.bind(common.mustCall(() => {
87+
assert.throws(() => {
88+
socket[functionName](size);
89+
}, common.expectsError(errorObj));
90+
socket.close();
91+
}));
92+
}
93+
94+
checkBufferSizeError('recv', 2147483648);
95+
checkBufferSizeError('send', 2147483648);

0 commit comments

Comments
 (0)