Skip to content

Commit 9cabd69

Browse files
authored
Collect log messages from rcl, and reset. (#2720)
* Collect log messages from rcl, and reset. Signed-off-by: Tomoya Fujita <[email protected]> * call rcl_reset_error once the error message is collected. Signed-off-by: Tomoya Fujita <[email protected]> * address CI failure, error is already collected and reset. Signed-off-by: Tomoya Fujita <[email protected]> --------- Signed-off-by: Tomoya Fujita <[email protected]>
1 parent a0a2a06 commit 9cabd69

File tree

10 files changed

+25
-6
lines changed

10 files changed

+25
-6
lines changed

rclcpp/include/rclcpp/event_handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ class EventHandler : public EventHandlerBase
278278
RCUTILS_LOG_ERROR_NAMED(
279279
"rclcpp",
280280
"Couldn't take event info: %s", rcl_get_error_string().str);
281+
rcl_reset_error();
281282
return nullptr;
282283
}
283284
return std::static_pointer_cast<void>(std::make_shared<EventCallbackInfoT>(callback_info));

rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
201201
RCUTILS_LOG_ERROR_NAMED(
202202
"rclcpp",
203203
"Couldn't add subscription to wait set: %s", rcl_get_error_string().str);
204+
rcl_reset_error();
204205
return false;
205206
}
206207
}
@@ -210,6 +211,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
210211
RCUTILS_LOG_ERROR_NAMED(
211212
"rclcpp",
212213
"Couldn't add client to wait set: %s", rcl_get_error_string().str);
214+
rcl_reset_error();
213215
return false;
214216
}
215217
}
@@ -219,6 +221,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
219221
RCUTILS_LOG_ERROR_NAMED(
220222
"rclcpp",
221223
"Couldn't add service to wait set: %s", rcl_get_error_string().str);
224+
rcl_reset_error();
222225
return false;
223226
}
224227
}
@@ -228,6 +231,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
228231
RCUTILS_LOG_ERROR_NAMED(
229232
"rclcpp",
230233
"Couldn't add timer to wait set: %s", rcl_get_error_string().str);
234+
rcl_reset_error();
231235
return false;
232236
}
233237
}

rclcpp/src/rclcpp/exceptions/exceptions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ throw_from_rcl_error(
9393
RCLErrorBase::RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state)
9494
: ret(ret), message(error_state->message), file(error_state->file), line(error_state->line_number),
9595
formatted_message(rcl_get_error_string().str)
96-
{}
96+
{
97+
rcl_reset_error();
98+
}
9799

98100
RCLError::RCLError(
99101
rcl_ret_t ret,

rclcpp/src/rclcpp/executor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ Executor::execute_subscription(rclcpp::SubscriptionBase::SharedPtr subscription)
568568
"rcl_return_loaned_message_from_subscription() failed for subscription on topic "
569569
"'%s': %s",
570570
subscription->get_topic_name(), rcl_get_error_string().str);
571+
rcl_reset_error();
571572
}
572573
loaned_msg = nullptr;
573574
}

rclcpp/src/rclcpp/node_interfaces/node_base.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ NodeBase::NodeBase(
132132
RCUTILS_LOG_ERROR_NAMED(
133133
"rclcpp",
134134
"Error in destruction of rosout publisher: %s", rcl_get_error_string().str);
135+
rcl_reset_error();
135136
}
136137
}
137138
}
138139
if (rcl_node_fini(node) != RCL_RET_OK) {
139140
RCUTILS_LOG_ERROR_NAMED(
140141
"rclcpp",
141142
"Error in destruction of rcl node handle: %s", rcl_get_error_string().str);
143+
rcl_reset_error();
142144
}
143145
delete node;
144146
});

rclcpp/src/rclcpp/node_interfaces/node_type_descriptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class NodeTypeDescriptions::NodeTypeDescriptionsImpl
105105
RCLCPP_ERROR(
106106
logger_, "Failed to initialize ~/get_type_description service: %s",
107107
rcl_get_error_string().str);
108+
rcl_reset_error();
108109
throw std::runtime_error(
109110
"Failed to initialize ~/get_type_description service.");
110111
}

rclcpp/src/rclcpp/serialized_message.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ SerializedMessage::~SerializedMessage()
122122
RCLCPP_ERROR(
123123
get_logger("rclcpp"),
124124
"Failed to destroy serialized message: %s", rcl_get_error_string().str);
125+
rcl_reset_error();
125126
}
126127
}
127128
}

rclcpp/test/rclcpp/strategies/test_allocator_memory_strategy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ TEST_F(TestAllocatorMemoryStrategy, add_handles_to_wait_set_bad_arguments) {
535535
});
536536
allocator_memory_strategy()->collect_entities(weak_groups_to_nodes);
537537
EXPECT_FALSE(allocator_memory_strategy()->add_handles_to_wait_set(nullptr));
538-
EXPECT_TRUE(rcl_error_is_set());
539-
rcl_reset_error();
538+
// The error message is collected and already reset.
539+
EXPECT_FALSE(rcl_error_is_set());
540540
}
541541

542542
TEST_F(TestAllocatorMemoryStrategy, add_handles_to_wait_set_subscription) {

rclcpp_action/src/server.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ ServerBase::ServerBase(
132132
if (RCL_RET_OK != ret) {
133133
RCLCPP_DEBUG(
134134
rclcpp::get_logger("rclcpp_action"),
135-
"failed to fini rcl_action_server_t in deleter");
135+
"failed to fini rcl_action_server_t in deleter: %s",
136+
rcl_get_error_string().str);
137+
rcl_reset_error();
136138
}
137139
delete ptr;
138140
}
@@ -424,7 +426,9 @@ ServerBase::execute_goal_request_received(
424426
if (RCL_RET_OK != fail_ret) {
425427
RCLCPP_DEBUG(
426428
rclcpp::get_logger("rclcpp_action"),
427-
"failed to fini rcl_action_goal_handle_t in deleter");
429+
"failed to fini rcl_action_goal_handle_t in deleter: %s",
430+
rcl_get_error_string().str);
431+
rcl_reset_error();
428432
}
429433
delete ptr;
430434
}

rclcpp_lifecycle/src/lifecycle_node_interface_impl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ LifecycleNode::LifecycleNodeInterfaceImpl::~LifecycleNodeInterfaceImpl()
7070
if (ret != RCL_RET_OK) {
7171
RCLCPP_FATAL(
7272
node_logging_interface_->get_logger(),
73-
"failed to destroy rcl_state_machine");
73+
"failed to destroy rcl_state_machine: %s",
74+
rcl_get_error_string().str);
75+
rcl_reset_error();
7476
}
7577
}
7678

@@ -405,6 +407,7 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
405407
node_logging_interface_->get_logger(),
406408
"Unable to change state for state machine for %s: %s",
407409
node_base_interface_->get_name(), rcl_get_error_string().str);
410+
rcl_reset_error();
408411
return RCL_RET_ERROR;
409412
}
410413

0 commit comments

Comments
 (0)