ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
124 stars 139 forks source link

Input validation for XML launch files #731

Open pac48 opened 12 months ago

pac48 commented 12 months ago

Feature request

Feature description

One of the advantages of using Python-based launch files as opposed to XML is the ability to validate input arguments and parameters. For example, if the launch file allows the user to set the arg robot_ip, it should not accept a malformed address. Instead, it would be nice if it informed the user of the mistake. Other than catching typos, input validation could potentially catch dependency issues, such as missing plugins. I believe validating string types would provide the most benefit, such as IP address, plugin names, file paths, etc. but numerical types could also be validated by checking upper or lower bounds.

In terms of implementation, there are several ways it can be expressed. The simplest solution is to add a regex tag that uses regex, e.g.

<arg name="robot_ip" default="127.0.0.1" regex="^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$"/>

A more elaborate solution could use dedicated tags for common validation types, e.g.

<arg name="robot_ip" default="127.0.0.1" validators="ip_address"/>
<arg name="web_server" default="http://127.0.0.1:8080" validators="url"/>
<arg name="dof" default="7" validators="one_of([6,7])"/>

I think there are other ways to achieve the same effect. I'm also interested in knowing how others might go about implementing it and what types of validations would provide the most value.

*credit to stackoverflow for IP regex

clalancette commented 11 months ago

We discussed this, and think that this is a good feature to have. Particularly the "validators" concept would be a very nice addition.

The place to start is probably to introduce the concept of a validator to the Python LaunchArgument; then we can extend it from there to support XML and YAML.

That said, we probably won't work on this in the near future. I'll place it on the backlog but please feel free to work on it and open a pull request if you are interested in doing that.