Skip to content

Commit 6a80223

Browse files
Improve axclient argument parsing (#189)
Strip trailing slash (equivalent to #132) Enforce that the suffix if found at the end of the profided string instead of anywhere in the string Report parser error instead of asserts with obscure error message Improve error message when topic type cannot be retrieved from ros master Enforce that goal topic is of *ActionGoal type instead of just *Goal type Signed-off-by: Mikael Arguedas <[email protected]>
1 parent e1338aa commit 6a80223

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Diff for: actionlib_tools/scripts/axclient.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,26 @@ def main():
232232

233233
(options, args) = parser.parse_args(rospy.myargv())
234234

235-
if (len(args) == 2):
235+
if len(args) == 2:
236236
# get action type via rostopic
237-
topic_type = rostopic._get_topic_type("%s/goal" % args[1])[0]
237+
action_name = args[1].rstrip('/')
238+
topic_type = rostopic._get_topic_type("%s/goal" % action_name)[0]
239+
if topic_type is None:
240+
parser.error("unable to retrieve the topic type for goal topic '{0}/goal'\nAre you sure the action server for '{0}' is running?".format(action_name))
238241
# remove "Goal" string from action type
239-
assert("Goal" in topic_type)
240-
topic_type = topic_type[0:len(topic_type)-4]
241-
elif (len(args) == 3):
242-
topic_type = args[2]
243-
print(topic_type)
244-
assert("Action" in topic_type)
242+
if not topic_type.endswith("ActionGoal"):
243+
parser.error("topic '%s/goal' is not an action goal topic" % action_name)
244+
action_type = topic_type[:-4]
245+
elif len(args) == 3:
246+
action_type = args[2]
247+
print(action_type)
248+
action_suffix = "Action"
249+
if not action_type.endswith(action_suffix):
250+
parser.error("the action type provided '%s' doesn't end with the '%s' suffix" % (action_type, action_suffix))
245251
else:
246252
parser.error("You must specify the action topic name (and optionally type) Eg: ./axclient.py action_topic actionlib/TwoIntsAction ")
247253

248-
action = DynamicAction(topic_type)
254+
action = DynamicAction(action_type)
249255
app = AXClientApp(action, args[1])
250256
app.MainLoop()
251257
app.OnQuit()

0 commit comments

Comments
 (0)