Skip to content

Commit d90e99c

Browse files
committed
src: use TryCatch.SetVerbose(true)
Signed-off-by: Darshan Sen <raisinten@gmail.com>
1 parent dfe4189 commit d90e99c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/dgram.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function startListening(socket) {
159159
const state = socket[kStateSymbol];
160160

161161
state.handle.onmessage = onMessage;
162-
// Todo: handle errors
162+
state.handle.onerror = onError;
163163
state.handle.recvStart();
164164
state.receiving = true;
165165
state.bindState = BIND_STATE_BOUND;
@@ -923,6 +923,12 @@ function onMessage(nread, handle, buf, rinfo) {
923923
}
924924

925925

926+
function onError(nread, handle, error) {
927+
const self = handle[owner_symbol];
928+
return self.emit('error', error);
929+
}
930+
931+
926932
Socket.prototype.ref = function() {
927933
const handle = this[kStateSymbol].handle;
928934

src/udp_wrap.cc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
#include "udp_wrap.h"
2323
#include "env-inl.h"
2424
#include "node_buffer.h"
25+
#include "node_errors.h"
2526
#include "node_sockaddr-inl.h"
2627
#include "handle_wrap.h"
2728
#include "req_wrap-inl.h"
2829
#include "util-inl.h"
2930

3031
namespace node {
3132

33+
using errors::TryCatchScope;
3234
using v8::Array;
3335
using v8::ArrayBuffer;
3436
using v8::BackingStore;
@@ -729,10 +731,32 @@ void UDPWrap::OnRecv(ssize_t nread,
729731
}
730732

731733
Local<Object> address;
732-
if (!AddressToJS(env, addr).ToLocal(&address)) return;
734+
{
735+
TryCatchScope try_catch(env);
736+
try_catch.SetVerbose(true);
737+
DCHECK(try_catch.IsVerbose());
738+
if (!AddressToJS(env, addr).ToLocal(&address)) {
739+
DCHECK(try_catch.HasCaught() && !try_catch.HasTerminated());
740+
argv[2] = try_catch.Exception();
741+
DCHECK(!argv[2].IsEmpty());
742+
MakeCallback(env->onerror_string(), arraysize(argv), argv);
743+
return;
744+
}
745+
}
733746

734747
Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, std::move(bs));
735-
argv[2] = Buffer::New(env, ab, 0, ab->ByteLength()).ToLocalChecked();
748+
{
749+
TryCatchScope try_catch(env);
750+
try_catch.SetVerbose(true);
751+
DCHECK(try_catch.IsVerbose());
752+
if (!Buffer::New(env, ab, 0, ab->ByteLength()).ToLocal(&argv[2])) {
753+
DCHECK(try_catch.HasCaught() && !try_catch.HasTerminated());
754+
argv[2] = try_catch.Exception();
755+
DCHECK(!argv[2].IsEmpty());
756+
MakeCallback(env->onerror_string(), arraysize(argv), argv);
757+
return;
758+
}
759+
}
736760
argv[3] = address;
737761
MakeCallback(env->onmessage_string(), arraysize(argv), argv);
738762
}

0 commit comments

Comments
 (0)