On error, ros2 launch command should point to the problematic launch file
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 155
- Forks
- 182
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 6
Description
Feature request
ros2 launch command errors are sometimes surprisingly unhelpful. For example, I have 2 launch files: broken.launch.xml, which has a syntax error, and main.launch.xml, which includes the previous script.
broken.launch.xml
<?xml version="1.0"?>
<launch>
<node pkg=""examples_rclcpp_minimal_publisher" exec="publisher_member_function" name="publisher_member_function" output="screen"/>
</launch>
main.launch.xml
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<include file="broken.launch.xml"/>
</launch>
If I try to run the main.launch.xml file (on galactic), I get this error:
$ ros2 launch main.launch.xml
[INFO] [launch]: All log files can be found below /home/sig/.ros/log/2022-08-02-00-49-31-890141-vr-desktop-2252539
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/galactic/lib/python3.8/site-packages/launch/launch_service.py:226> exception=InvalidLaunchFileError('xml')>
Traceback (most recent call last):
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/frontend/parser.py", line 177, in load
return implementation.load(fileobj)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch_xml/parser.py", line 35, in load
return (Entity(ET.parse(file).getroot()), cls())
File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1202, in parse
tree.parse(source, parser)
File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 595, in parse
self._root = parser._parse_whole(source)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 3, column 13
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 53, in get_launch_description_from_any_launch_file
return loader(launch_file_path)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/frontend_launch_file_utilities.py", line 34, in get_launch_description_from_frontend_launch_file
root_entity, parser = parser.load(frontend_launch_file_path)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/frontend/parser.py", line 182, in load
raise InvalidFrontendLaunchFileError(extension, likely_errors=exceptions)
launch.frontend.parser.InvalidFrontendLaunchFileError: Caught exception when trying to load file of format [xml]: not well-formed (invalid token): line 3, column 13
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/galactic/lib/python3.8/site-packages/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 "/opt/ros/galactic/lib/python3.8/site-packages/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 "/opt/ros/galactic/lib/python3.8/site-packages/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)
[Previous line repeated 1 more time]
File "/opt/ros/galactic/lib/python3.8/site-packages/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 "/opt/ros/galactic/lib/python3.8/site-packages/launch/action.py", line 108, in visit
return self.execute(context)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/actions/include_launch_description.py", line 127, in execute
launch_description = self.__launch_description_source.get_launch_description(context)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_source.py", line 84, in get_launch_description
self._get_launch_description(self.__expanded_location)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_description_source.py", line 53, in _get_launch_description
return get_launch_description_from_any_launch_file(location)
File "/opt/ros/galactic/lib/python3.8/site-packages/launch/launch_description_sources/any_launch_file_utilities.py", line 56, in get_launch_description_from_any_launch_file
raise InvalidLaunchFileError(extension, likely_errors=exceptions)
launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [xml]: Caught exception when trying to load file of format [xml]: not well-formed (invalid token): line 3, column 1
Besides the verbose output, you can notice the error contains no information about the offending file. I know one of my xml files has an issue (and exactly at line 3, column 1), but I don't know which. In this toy example, I just have 2 files so pinning down to the broken file would be easy. Of course when the launch system is composed of hundreds of xml files that's another story.
Feature description
Any failure while launching a file (malformed xml, missing argument...) should explicitly give the path to the offending file
Implementation considerations
I could be done by adding path information to errors like InvalidLaunchFileError
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at launch/launch_description_sources/any_launch_file_utilities.py and launch/launch_description_sources/frontend_launch_file_utilities.py, then trace how launch/actions/include_launch_description.py loads nested files. Reproduce the malformed XML case with ros2 launch and inspect InvalidLaunchFileError propagation. Done means failures identify the offending launch-file path, including nested includes, while retaining the existing parse details.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100