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

Improve error reporting by adding file locations to exceptions #823

Open
wants to merge 3 commits into
base: rolling
Choose a base branch
from

Conversation

rolker
Copy link

@rolker rolker commented Jan 28, 2025

In order to pinpoint which launch file caused an exception, this patch intercepts exceptions and adds notes that help determine the source of the error.

This might help with #799 as well.

Copy link
Member

@christophebedard christophebedard left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Could you add simple before/after example outputs in the PR description (including the commands you ran to get the output, if possible) to show how this improves error reporting?

declared_launch_arguments = (
launch_description.get_launch_arguments_with_include_launch_description_actions())
except Exception as exc:
exc.add_note('while executing {}'.format(self.describe()))
Copy link
Member

Choose a reason for hiding this comment

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

Could you switch to f-strings, here and everywhere else?

Copy link
Author

Choose a reason for hiding this comment

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

Python is not my native programming language so I had to google f-strings and learned something useful. Thanks!

@rolker
Copy link
Author

rolker commented Jan 29, 2025

Example output using https://github.com/rolker/launch_error_examples

This is a simpler set of launch files than what I was dealing with when I created the patch, but still has some nested includes to better showcase the issue when dealing with complex launch files.

It should be noted that this helps with error that pop up when the launch description is executed. Errors while loading/evaluating the files tend to display the file location of the error.

Before the patch:

$ ros2 launch launch_error_example parent_launch.py 
[INFO] [launch]: All log files can be found below /home/roland/.ros/log/2025-01-29-10-47-00-892280-deadpool-41786
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'tuple' object has no attribute 'describe_sub_entities'

$ ros2 launch -d launch_error_example parent_launch.py 
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.IncludeLaunchDescription'
[INFO] [launch]: All log files can be found below /home/roland/.ros/log/2025-01-29-10-47-44-260437-deadpool-42338
[INFO] [launch]: Default logging verbosity is set to DEBUG
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x74d3999bc740>'
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x74d3999bc740>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x74d3999bc860>'
[DEBUG] [launch]: An exception was raised in an async action/event
[DEBUG] [launch]: Traceback (most recent call last):
  File "/home/roland/ros2/rolling/build/launch/launch/launch_service.py", line 343, in run_async
    raise exception_to_raise
  File "/home/roland/ros2/rolling/build/launch/launch/launch_service.py", line 230, in _process_one_event
    await self.__process_event(next_event)
  File "/home/roland/ros2/rolling/build/launch/launch/launch_service.py", line 250, in __process_event
    visit_all_entities_and_collect_futures(entity, self.__context))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
    futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
    futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
    sub_entities = entity.visit(context)
                  ^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/action.py", line 109, in visit
    return self.execute(context)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/actions/include_launch_description.py", line 164, in execute
    launch_description.get_launch_arguments_with_include_launch_description_actions())
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 161, in get_launch_arguments_with_include_launch_description_actions
    process_entities(self.entities, _conditional_inclusion=conditional_inclusion)
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 151, in process_entities
    process_entities(
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 151, in process_entities
    process_entities(
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 152, in process_entities
    entity.describe_sub_entities(),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'describe_sub_entities'

[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'tuple' object has no attribute 'describe_sub_entities'
[DEBUG] [launch.launch_context]: emitting event: 'launch.events.Shutdown'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x74d399ade420>'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x74d399ade420>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x74d399900ce0>'

With this patch applied. Notice the added info where the exception is printed with the added notes.

$ ros2 launch launch_error_example parent_launch.py 
[INFO] [launch]: All log files can be found below /home/roland/.ros/log/2025-01-29-10-50-46-363663-deadpool-45119
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'tuple' object has no attribute 'describe_sub_entities'

$ ros2 launch -d launch_error_example parent_launch.py 
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.IncludeLaunchDescription'
[INFO] [launch]: All log files can be found below /home/roland/.ros/log/2025-01-29-10-51-29-159327-deadpool-45707
[INFO] [launch]: Default logging verbosity is set to DEBUG
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x79c2e55cc4d0>'
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x79c2e55cc4d0>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x79c2e55cecf0>'
[DEBUG] [launch]: An exception was raised in an async action/event
[DEBUG] [launch]: Traceback (most recent call last):
  File "/home/roland/ros2/rolling/build/launch/launch/launch_service.py", line 343, in run_async
    raise exception_to_raise
  File "/home/roland/ros2/rolling/build/launch/launch/launch_service.py", line 230, in _process_one_event
    await self.__process_event(next_event)
  File "/home/roland/ros2/rolling/build/launch/launch/launch_service.py", line 250, in __process_event
    visit_all_entities_and_collect_futures(entity, self.__context))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
    futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
    futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
    sub_entities = entity.visit(context)
                  ^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/action.py", line 109, in visit
    return self.execute(context)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/actions/include_launch_description.py", line 166, in execute
    launch_description.get_launch_arguments_with_include_launch_description_actions())
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 165, in get_launch_arguments_with_include_launch_description_actions
    process_entities(self.entities, _conditional_inclusion=conditional_inclusion)
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 152, in process_entities
    process_entities(
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 152, in process_entities
    process_entities(
  File "/home/roland/ros2/rolling/build/launch/launch/launch_description.py", line 153, in process_entities
    entity.describe_sub_entities(),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'describe_sub_entities'
entity: (IncludeLaunchDescription(PathJoin('FindPackageShare(pkg='turtlesim') + 'launch' + 'multisim.launch.py'')),)
entity: <launch.launch_description.LaunchDescription object at 0x79c2e543be30>
entity: IncludeLaunchDescription(PathJoin('FindPackageShare(pkg='launch_error_example') + 'launch' + 'bar_launch.py''))
while executing IncludeLaunchDescription(/home/roland/ros2/rolling/install/launch_error_example/share/launch_error_example/launch/parent_launch.py)

[ERROR] [launch]: Caught exception in launch (see debug for traceback): 'tuple' object has no attribute 'describe_sub_entities'
[DEBUG] [launch.launch_context]: emitting event: 'launch.events.Shutdown'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x79c2e5ef0110>'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x79c2e5ef0110>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x79c2e5555520>'

Signed-off-by: Roland Arsenault <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants