Skip to content

Improve error reporting by adding file locations to exceptions#823

Merged
christophebedard merged 7 commits intoros2:rollingfrom
rolker:improve_error_reporting
Feb 12, 2025
Merged

Improve error reporting by adding file locations to exceptions#823
christophebedard merged 7 commits intoros2:rollingfrom
rolker:improve_error_reporting

Conversation

@rolker
Copy link
Copy Markdown
Contributor

@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.

Signed-off-by: Roland Arsenault <roland@ccom.unh.edu>
Signed-off-by: Roland Arsenault <roland@ccom.unh.edu>
Copy link
Copy Markdown
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?

@rolker
Copy link
Copy Markdown
Contributor 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 <roland@ccom.unh.edu>
rolker and others added 2 commits February 10, 2025 08:20
Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Roland Arsenault <roland@rolker.net>
Signed-off-by: Roland Arsenault <roland@ccom.unh.edu>
@christophebedard
Copy link
Copy Markdown
Member

Pulls: #823
Gist: https://gist.githubusercontent.com/christophebedard/2bff873eec3a4a273b4df0defdc3ea19/raw/25881a289532c4d418c970c5ce5a626d44808c8e/ros2.repos
BUILD args: --packages-above-and-dependencies launch
TEST args: --packages-above launch
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15156

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

… add_note

Signed-off-by: Roland Arsenault <roland@ccom.unh.edu>
@christophebedard
Copy link
Copy Markdown
Member

Thanks for the fix! New CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Copy link
Copy Markdown
Contributor

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

@christophebedard
Copy link
Copy Markdown
Member

lgtm, (this does not block the PR) how about adding the test around https://github.com/ros2/launch/blob/rolling/launch/test/launch/actions/test_include_launch_description.py?

If @rolker wants to, but I don't think we need anything fancy here.

Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Roland Arsenault <roland@rolker.net>
@rolker
Copy link
Copy Markdown
Contributor Author

rolker commented Feb 12, 2025

lgtm, (this does not block the PR) how about adding the test around https://github.com/ros2/launch/blob/rolling/launch/test/launch/actions/test_include_launch_description.py?

If @rolker wants to, but I don't think we need anything fancy here.

I need to focus on my main tasks at the moment so I'll pass for now. I'd like to revisit some of this at some later time when I have a few more spare cycles.

@christophebedard
Copy link
Copy Markdown
Member

New-new CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@christophebedard christophebedard merged commit ce9a0ca into ros2:rolling Feb 12, 2025
2 checks passed
@christophebedard
Copy link
Copy Markdown
Member

Thanks again for the PR and for persisting!

@rolker
Copy link
Copy Markdown
Contributor Author

rolker commented Feb 13, 2025

Your welcome and thanks for guiding me through!

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.

3 participants