Skip to content

Commit

Permalink
[roslaunch] Better exception handling when resource is not found.
Browse files Browse the repository at this point in the history
When `$(find pkg)` fail to return a resource in `arg` tag, `roslaunch` fails without printing useful output. With this PR it provides better explanation.

Without this PR:
```
$ roslaunch /tmp/invalid_arg.launch
:
Invalid <arg> tag: foo
ROS path [0]=/opt/ros/kinetic/share/ros
ROS path [1]=/home/n130s/ROS/indigo_trusty/cws_rosdt/src/ros/ros_comm/tools/roslaunch
ROS path [2]=/opt/ros/kinetic/share

Arg xml is <arg default="$(find foo)/.config" name="foo"/>
The traceback for the exception was written to the log file
```

With this PR:
```
$ roslaunch /tmp/invalid_arg.launch
:
Invalid <arg> tag: Make sure the following is found in ROS_PACKAGE_PATH: foo
ROS path [0]=/opt/ros/kinetic/share/ros
ROS path [1]=/home/n130s/ROS/indigo_trusty/cws_rosdt/src/ros/ros_comm/tools/roslaunch
ROS path [2]=/opt/ros/kinetic/share

Arg xml is <arg default="$(find foo)/.config" name="foo"/>
The traceback for the exception was written to the log file
```

```
$ more /tmp/invalid_arg.launch
<?xml version="1.0"?>
<launch>
  <arg name="foo" default="$(find foo)/.config" />
  <arg name="baa" default="$(arg foo)/hoge.yaml" />
</launch>
```
  • Loading branch information
130s committed Aug 9, 2018
1 parent 678ad4f commit 93ddea2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/roslaunch/src/roslaunch/xmlloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from xml.dom import Node as DomNode #avoid aliasing

from rosgraph.names import make_global_ns, ns_join, is_private, is_legal_name, get_ros_namespace
from rospkg import ResourceNotFound

from .core import Param, Node, Test, Machine, RLException
from . import loader
Expand Down Expand Up @@ -301,6 +302,9 @@ def _arg_tag(self, tag, context, ros_config, verbose=True):
except substitution_args.ArgException as e:
raise XmlParseException(
"arg '%s' is not defined. \n\nArg xml is %s"%(e, tag.toxml()))
except ResourceNotFound as e:
raise XmlParseException(
"Invalid <arg> tag: Make sure the following is found in ROS_PACKAGE_PATH: %s \n\nArg xml is %s"%(e, tag.toxml()))
except Exception as e:
raise XmlParseException(
"Invalid <arg> tag: %s. \n\nArg xml is %s"%(e, tag.toxml()))
Expand Down

0 comments on commit 93ddea2

Please sign in to comment.