Skip to content

Commit aa634b2

Browse files
Clearer warning message, the old one lacked information and was perhaps misleading (#2927) (#2931)
* change misleading warning message, making it more correct and informative * Fix compile error. Needed to also build rcl from source. * explicitely initialize pointer as null, to adhere to best practice --------- (cherry picked from commit 3767779) Signed-off-by: Peter Mitrano (AR) <[email protected]> Co-authored-by: Peter Mitrano (AR) <[email protected]>
1 parent 8ec31ed commit aa634b2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

rclcpp_lifecycle/src/lifecycle_node_interface_impl.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
390390
constexpr bool publish_update = true;
391391
State initial_state;
392392
unsigned int current_state_id;
393+
const rcl_lifecycle_transition_t * original_transition{nullptr};
393394

394395
{
395396
std::lock_guard<std::recursive_mutex> lock(state_machine_mutex_);
@@ -405,6 +406,10 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
405406
// keep the initial state to pass to a transition callback
406407
initial_state = State(state_machine_.current_state);
407408

409+
original_transition =
410+
rcl_lifecycle_get_transition_by_id(state_machine_.current_state, transition_id);
411+
412+
408413
if (
409414
rcl_lifecycle_trigger_transition_by_id(
410415
&state_machine_, transition_id, publish_update) != RCL_RET_OK)
@@ -455,12 +460,15 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
455460
// Update the internal current_state_
456461
current_state_ = State(state_machine_.current_state);
457462

458-
// error handling ?!
463+
// error handling
459464
// TODO(karsten1987): iterate over possible ret value
460465
if (cb_return_code == node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR) {
461-
RCLCPP_WARN(
462-
node_logging_interface_->get_logger(),
463-
"Error occurred while doing error handling.");
466+
if (original_transition) {
467+
RCLCPP_WARN(
468+
node_logging_interface_->get_logger(),
469+
"Callback returned ERROR during the transition: %s", original_transition->label);
470+
}
471+
464472

465473
auto error_cb_code = execute_callback(current_state_id, initial_state);
466474
auto error_cb_label = get_label_for_return_code(error_cb_code);

0 commit comments

Comments
 (0)