Skip to content

Commit 41d3a27

Browse files
authored
print warning if event callback is not supported instead of passing exception. (#2648)
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent c50f0c9 commit 41d3a27

File tree

2 files changed

+83
-34
lines changed

2 files changed

+83
-34
lines changed

rclcpp/src/rclcpp/publisher_base.cpp

+36-16
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,28 @@ void
135135
PublisherBase::bind_event_callbacks(
136136
const PublisherEventCallbacks & event_callbacks, bool use_default_callbacks)
137137
{
138-
if (event_callbacks.deadline_callback) {
139-
this->add_event_handler(
140-
event_callbacks.deadline_callback,
141-
RCL_PUBLISHER_OFFERED_DEADLINE_MISSED);
138+
try {
139+
if (event_callbacks.deadline_callback) {
140+
this->add_event_handler(
141+
event_callbacks.deadline_callback,
142+
RCL_PUBLISHER_OFFERED_DEADLINE_MISSED);
143+
}
144+
} catch (const UnsupportedEventTypeException & /*exc*/) {
145+
RCLCPP_WARN(
146+
rclcpp::get_logger("rclcpp"),
147+
"Failed to add event handler for deadline; not supported");
142148
}
143-
if (event_callbacks.liveliness_callback) {
144-
this->add_event_handler(
145-
event_callbacks.liveliness_callback,
146-
RCL_PUBLISHER_LIVELINESS_LOST);
149+
150+
try {
151+
if (event_callbacks.liveliness_callback) {
152+
this->add_event_handler(
153+
event_callbacks.liveliness_callback,
154+
RCL_PUBLISHER_LIVELINESS_LOST);
155+
}
156+
} catch (const UnsupportedEventTypeException & /*exc*/) {
157+
RCLCPP_WARN(
158+
rclcpp::get_logger("rclcpp"),
159+
"Failed to add event handler for liveliness; not supported");
147160
}
148161

149162
QOSOfferedIncompatibleQoSCallbackType incompatible_qos_cb;
@@ -160,9 +173,9 @@ PublisherBase::bind_event_callbacks(
160173
this->add_event_handler(incompatible_qos_cb, RCL_PUBLISHER_OFFERED_INCOMPATIBLE_QOS);
161174
}
162175
} catch (const UnsupportedEventTypeException & /*exc*/) {
163-
RCLCPP_DEBUG(
176+
RCLCPP_WARN(
164177
rclcpp::get_logger("rclcpp"),
165-
"Failed to add event handler for incompatible qos; wrong callback type");
178+
"Failed to add event handler for incompatible qos; not supported");
166179
}
167180

168181
IncompatibleTypeCallbackType incompatible_type_cb;
@@ -179,14 +192,21 @@ PublisherBase::bind_event_callbacks(
179192
this->add_event_handler(incompatible_type_cb, RCL_PUBLISHER_INCOMPATIBLE_TYPE);
180193
}
181194
} catch (UnsupportedEventTypeException & /*exc*/) {
182-
RCLCPP_DEBUG(
195+
RCLCPP_WARN(
183196
rclcpp::get_logger("rclcpp"),
184-
"Failed to add event handler for incompatible type; wrong callback type");
197+
"Failed to add event handler for incompatible type; not supported");
185198
}
186-
if (event_callbacks.matched_callback) {
187-
this->add_event_handler(
188-
event_callbacks.matched_callback,
189-
RCL_PUBLISHER_MATCHED);
199+
200+
try {
201+
if (event_callbacks.matched_callback) {
202+
this->add_event_handler(
203+
event_callbacks.matched_callback,
204+
RCL_PUBLISHER_MATCHED);
205+
}
206+
} catch (const UnsupportedEventTypeException & /*exc*/) {
207+
RCLCPP_WARN(
208+
rclcpp::get_logger("rclcpp"),
209+
"Failed to add event handler for matched; not supported");
190210
}
191211
}
192212

rclcpp/src/rclcpp/subscription_base.cpp

+47-18
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,28 @@ void
112112
SubscriptionBase::bind_event_callbacks(
113113
const SubscriptionEventCallbacks & event_callbacks, bool use_default_callbacks)
114114
{
115-
if (event_callbacks.deadline_callback) {
116-
this->add_event_handler(
117-
event_callbacks.deadline_callback,
118-
RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED);
115+
try {
116+
if (event_callbacks.deadline_callback) {
117+
this->add_event_handler(
118+
event_callbacks.deadline_callback,
119+
RCL_SUBSCRIPTION_REQUESTED_DEADLINE_MISSED);
120+
}
121+
} catch (const UnsupportedEventTypeException & /*exc*/) {
122+
RCLCPP_WARN(
123+
rclcpp::get_logger("rclcpp"),
124+
"Failed to add event handler for deadline; not supported");
119125
}
120126

121-
if (event_callbacks.liveliness_callback) {
122-
this->add_event_handler(
123-
event_callbacks.liveliness_callback,
124-
RCL_SUBSCRIPTION_LIVELINESS_CHANGED);
127+
try {
128+
if (event_callbacks.liveliness_callback) {
129+
this->add_event_handler(
130+
event_callbacks.liveliness_callback,
131+
RCL_SUBSCRIPTION_LIVELINESS_CHANGED);
132+
}
133+
} catch (const UnsupportedEventTypeException & /*exc*/) {
134+
RCLCPP_WARN(
135+
rclcpp::get_logger("rclcpp"),
136+
"Failed to add event handler for liveliness; not supported");
125137
}
126138

127139
QOSRequestedIncompatibleQoSCallbackType incompatible_qos_cb;
@@ -139,7 +151,9 @@ SubscriptionBase::bind_event_callbacks(
139151
this->add_event_handler(incompatible_qos_cb, RCL_SUBSCRIPTION_REQUESTED_INCOMPATIBLE_QOS);
140152
}
141153
} catch (const UnsupportedEventTypeException & /*exc*/) {
142-
// pass
154+
RCLCPP_WARN(
155+
rclcpp::get_logger("rclcpp"),
156+
"Failed to add event handler for incompatible qos; not supported");
143157
}
144158

145159
IncompatibleTypeCallbackType incompatible_type_cb;
@@ -156,18 +170,33 @@ SubscriptionBase::bind_event_callbacks(
156170
this->add_event_handler(incompatible_type_cb, RCL_SUBSCRIPTION_INCOMPATIBLE_TYPE);
157171
}
158172
} catch (UnsupportedEventTypeException & /*exc*/) {
159-
// pass
173+
RCLCPP_WARN(
174+
rclcpp::get_logger("rclcpp"),
175+
"Failed to add event handler for incompatible type; not supported");
160176
}
161177

162-
if (event_callbacks.message_lost_callback) {
163-
this->add_event_handler(
164-
event_callbacks.message_lost_callback,
165-
RCL_SUBSCRIPTION_MESSAGE_LOST);
178+
try {
179+
if (event_callbacks.message_lost_callback) {
180+
this->add_event_handler(
181+
event_callbacks.message_lost_callback,
182+
RCL_SUBSCRIPTION_MESSAGE_LOST);
183+
}
184+
} catch (const UnsupportedEventTypeException & /*exc*/) {
185+
RCLCPP_WARN(
186+
rclcpp::get_logger("rclcpp"),
187+
"Failed to add event handler for message lost; not supported");
166188
}
167-
if (event_callbacks.matched_callback) {
168-
this->add_event_handler(
169-
event_callbacks.matched_callback,
170-
RCL_SUBSCRIPTION_MATCHED);
189+
190+
try {
191+
if (event_callbacks.matched_callback) {
192+
this->add_event_handler(
193+
event_callbacks.matched_callback,
194+
RCL_SUBSCRIPTION_MATCHED);
195+
}
196+
} catch (const UnsupportedEventTypeException & /*exc*/) {
197+
RCLCPP_WARN(
198+
rclcpp::get_logger("rclcpp"),
199+
"Failed to add event handler for matched; not supported");
171200
}
172201
}
173202

0 commit comments

Comments
 (0)