Skip to content

Commit de7f83c

Browse files
Clearer warning message, the old one lacked information and was perhaps misleading (#2927) (#2932)
* 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 2096d63 commit de7f83c

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
@@ -397,6 +397,7 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
397397
constexpr bool publish_update = true;
398398
State initial_state;
399399
unsigned int current_state_id;
400+
const rcl_lifecycle_transition_t * original_transition{nullptr};
400401

401402
{
402403
std::lock_guard<std::recursive_mutex> lock(state_machine_mutex_);
@@ -411,6 +412,10 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
411412
// keep the initial state to pass to a transition callback
412413
initial_state = State(state_machine_.current_state);
413414

415+
original_transition =
416+
rcl_lifecycle_get_transition_by_id(state_machine_.current_state, transition_id);
417+
418+
414419
if (
415420
rcl_lifecycle_trigger_transition_by_id(
416421
&state_machine_, transition_id, publish_update) != RCL_RET_OK)
@@ -461,12 +466,15 @@ LifecycleNode::LifecycleNodeInterfaceImpl::change_state(
461466
// Update the internal current_state_
462467
current_state_ = State(state_machine_.current_state);
463468

464-
// error handling ?!
469+
// error handling
465470
// TODO(karsten1987): iterate over possible ret value
466471
if (cb_return_code == node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR) {
467-
RCLCPP_WARN(
468-
node_logging_interface_->get_logger(),
469-
"Error occurred while doing error handling.");
472+
if (original_transition) {
473+
RCLCPP_WARN(
474+
node_logging_interface_->get_logger(),
475+
"Callback returned ERROR during the transition: %s", original_transition->label);
476+
}
477+
470478

471479
auto error_cb_code = execute_callback(current_state_id, initial_state);
472480
auto error_cb_label = get_label_for_return_code(error_cb_code);

0 commit comments

Comments
 (0)