Skip to content

Commit 1f87ba4

Browse files
committed
Address comments
1 parent 3306f23 commit 1f87ba4

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/rcl_subscription_bindings.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,26 @@ Napi::Value CreateSubscription(const Napi::CallbackInfo& info) {
127127
GetMessageTypeSupport(package_name, message_sub_folder, message_name);
128128

129129
if (ts) {
130-
THROW_ERROR_IF_NOT_EQUAL(
131-
RCL_RET_OK,
132-
rcl_subscription_init(subscription, node, ts, topic.c_str(),
133-
&subscription_ops),
134-
rcl_get_error_string().str);
130+
rcl_ret_t ret = rcl_subscription_init(subscription, node, ts, topic.c_str(),
131+
&subscription_ops);
132+
if (ret != RCL_RET_OK) {
133+
std::string error_msg = rcl_get_error_string().str;
134+
rcl_reset_error();
135+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
136+
return env.Undefined();
137+
}
135138

136139
auto js_obj = RclHandle::NewInstance(
137140
env, subscription, node_handle, [node, env](void* ptr) {
138141
rcl_subscription_t* subscription =
139142
reinterpret_cast<rcl_subscription_t*>(ptr);
140143
rcl_ret_t ret = rcl_subscription_fini(subscription, node);
141144
free(ptr);
142-
THROW_ERROR_IF_NOT_EQUAL_NO_RETURN(RCL_RET_OK, ret,
143-
rcl_get_error_string().str);
145+
if (ret != RCL_RET_OK) {
146+
std::string error_msg = rcl_get_error_string().str;
147+
rcl_reset_error();
148+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
149+
}
144150
});
145151

146152
return js_obj;
@@ -346,9 +352,9 @@ Napi::Value GetContentFilter(const Napi::CallbackInfo& info) {
346352

347353
rcl_ret_t ret = rcl_subscription_get_content_filter(subscription, &options);
348354
if (ret != RCL_RET_OK) {
349-
Napi::Error::New(env, rcl_get_error_string().str)
350-
.ThrowAsJavaScriptException();
355+
std::string error_msg = rcl_get_error_string().str;
351356
rcl_reset_error();
357+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
352358
return env.Undefined();
353359
}
354360

@@ -374,9 +380,9 @@ Napi::Value GetContentFilter(const Napi::CallbackInfo& info) {
374380
rcl_ret_t fini_ret =
375381
rcl_subscription_content_filter_options_fini(subscription, &options);
376382
if (fini_ret != RCL_RET_OK) {
377-
Napi::Error::New(env, rcl_get_error_string().str)
378-
.ThrowAsJavaScriptException();
383+
std::string error_msg = rcl_get_error_string().str;
379384
rcl_reset_error();
385+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
380386
return env.Undefined();
381387
}
382388

@@ -390,9 +396,12 @@ Napi::Value GetPublisherCount(const Napi::CallbackInfo& info) {
390396
RclHandle::Unwrap(info[0].As<Napi::Object>())->ptr());
391397

392398
size_t count = 0;
393-
THROW_ERROR_IF_NOT_EQUAL(
394-
rcl_subscription_get_publisher_count(subscription, &count), RCL_RET_OK,
395-
rcl_get_error_string().str);
399+
rcl_ret_t ret = rcl_subscription_get_publisher_count(subscription, &count);
400+
if (ret != RCL_RET_OK) {
401+
std::string error_msg = rcl_get_error_string().str;
402+
rcl_reset_error();
403+
Napi::Error::New(env, error_msg).ThrowAsJavaScriptException();
404+
}
396405

397406
return Napi::Number::New(env, count);
398407
}

0 commit comments

Comments
 (0)