Skip to content

Commit 9ad994b

Browse files
committed
dgram: migrate bufferSize to use internal/errors
PR-URL: #16567 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 3d9d849 commit 9ad994b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/dgram.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ function bufferSize(self, size, buffer) {
173173
if (size >>> 0 !== size)
174174
throw new errors.TypeError('ERR_SOCKET_BAD_BUFFER_SIZE');
175175

176-
try {
177-
return self._handle.bufferSize(size, buffer);
178-
} catch (e) {
179-
throw new errors.Error('ERR_SOCKET_BUFFER_SIZE', e);
176+
const ctx = {};
177+
const ret = self._handle.bufferSize(size, buffer, ctx);
178+
if (ret === undefined) {
179+
throw new errors.Error('ERR_SOCKET_BUFFER_SIZE',
180+
new errors.SystemError(ctx));
180181
}
182+
return ret;
181183
}
182184

183185
Socket.prototype.bind = function(port_, address_ /*, callback*/) {

src/udp_wrap.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
234234
const char* uv_func_name = is_recv ? "uv_recv_buffer_size" :
235235
"uv_send_buffer_size";
236236

237-
if (!args[0]->IsInt32())
238-
return env->ThrowUVException(UV_EINVAL, uv_func_name);
237+
if (!args[0]->IsInt32()) {
238+
env->CollectUVExceptionInfo(args[2], UV_EINVAL, uv_func_name);
239+
return args.GetReturnValue().SetUndefined();
240+
}
239241

240242
uv_handle_t* handle = reinterpret_cast<uv_handle_t*>(&wrap->handle_);
241243
int size = static_cast<int>(args[0].As<Uint32>()->Value());
@@ -246,8 +248,10 @@ void UDPWrap::BufferSize(const FunctionCallbackInfo<Value>& args) {
246248
else
247249
err = uv_send_buffer_size(handle, &size);
248250

249-
if (err != 0)
250-
return env->ThrowUVException(err, uv_func_name);
251+
if (err != 0) {
252+
env->CollectUVExceptionInfo(args[2], err, uv_func_name);
253+
return args.GetReturnValue().SetUndefined();
254+
}
251255

252256
args.GetReturnValue().Set(size);
253257
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ function checkBufferSizeError(type, size) {
7777
const errorObj = {
7878
code: 'ERR_SOCKET_BUFFER_SIZE',
7979
type: Error,
80-
message: 'Could not get or set buffer size: Error: EINVAL: ' +
81-
`invalid argument, uv_${type}_buffer_size`
80+
message: /^Could not get or set buffer size:.*$/
8281
};
8382
const functionName = `set${type.charAt(0).toUpperCase()}${type.slice(1)}` +
8483
'BufferSize';

0 commit comments

Comments
 (0)