launch: eval substitution errors

Bug report

Required Info:

  • Operating System: Ubuntu 20.04
  • Installation type: Binaries
  • Version or commit hash: foxy latest release
  • DDS implementation: Fast-RTPS
  • Client library (if applicable): N/A

Steps to reproduce issue

Create and launch a xml launch file like this

<launch>
  <let name="variable" value="val1"/>
  <node pkg="demo_nodes_cpp" exec="talker if="$(eval variable == 'val1')" output="screen" />
</launch>

Expected behavior

talker starts running

Actual behavior

I get this error: TypeError: eval substitution expects 1 argument

Additional information

It seems that spaces confuse the eval substitution. Even if I remove the spaces, launch fails with

launch.invalid_launch_file_error.InvalidLaunchFileError: Caught exception when trying to load file of format [xml]: No terminal defined for ''' at line 1 col 20

$(eval variable=='val1')
                 ^

Expecting: {'UNQUOTED_RSTRING', 'SPACE', 'RPAR', 'DOLLAR'}

which I guess means that it doesn’t like the single quote character

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 6
  • Comments: 18 (13 by maintainers)

Most upvoted comments

I get this error: TypeError: eval substitution expects 1 argument

That’s because the Python expression substitution expects a single argument. Making the argument a single string and escaping single quotes accordingly should work:

If this is the designed behavior, this is not compatible with ROS1 and I suggest that it would be documented somewhere. In the tutorials it explicitly says that stayed the same, so many (myself included) might believe that these substitutions can be copy-pasted to ROS2 launch files. The arguments of each substitution could be added here https://design.ros2.org/articles/roslaunch_xml.html.

Marking this as help wanted, @hidmic @wjwwood feel free to undo it if it doesn’t seem appropriate.

@Thodoris1999 if you want to address the issue, it involves modifying the parse method here to handle any number of arguments, instead of one, and joining all of them.

If you open a PR or need some help, feel free to tag me.

I have a related error where the evaluation cannot recognize the arg. Unsure if I should open a new issue as it is related to this one.

Steps to reproduce Create and launch a xml launch file like this

<launch>
  <arg name="variable" value="val1"/>
  <node pkg="demo_nodes_cpp" exec="talker if="$(eval 'variable == \'val1\'')" output="screen" />
</launch>

Expected behavior talker starts running

Actual Behaviour NameError: name 'variable' is not defined

I am running within the latest foxy base docker image. I would really appreciate pointers on what I might be going wrong!

I like the idea of adding an exception (or rule, whatever you want to call it) to allows us to avoid escaping. Because it gets us closer to ROS 1 behavior, helping migrators out, and because it’s just more convenient. But I don’t feel strongly about it, and I’m not the one doing the work (AFAIK 😄), so it’s up to you guys.