Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject wrong lifecycle transitions without crash (#1209) #1317

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rclpy/rclpy/lifecycle/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ def __on_change_state(
):
self.__check_is_initialized()
transition_id = req.transition.id

available_transition_ids = [t[0] for t in self._state_machine.available_transitions]
if transition_id not in available_transition_ids:
resp.success = False
return resp

Comment on lines +353 to +358
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the stack trace from #1209 (comment), the root cause of this exception is from __change_state. i think what we should do here is to catch the exception from the failure from rcl transition change, and print the error for user application.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This PR only addresses the issue of external state changes through the "change_state" service.
Modifying __change_state is more appropriate.

if req.transition.label:
try:
transition_id = self._state_machine.get_transition_by_label(req.transition.label)
Expand Down