Skip to content

Commit

Permalink
Move try-except to verb
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Apr 13, 2019
1 parent 71de0e5 commit bbd8893
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
10 changes: 2 additions & 8 deletions ros2action/ros2action/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ def get_action_clients_and_servers(*, node, action_name):
action_clients = []
action_servers = []

try:
expanded_name = expand_topic_name(action_name, node.get_name(), node.get_namespace())
except ValueError as e:
raise RuntimeError(e)
try:
validate_full_topic_name(expanded_name)
except rclpy.exceptions.InvalidTopicNameException as e:
raise RuntimeError(e)
expanded_name = expand_topic_name(action_name, node.get_name(), node.get_namespace())
validate_full_topic_name(expanded_name)

node_names_and_ns = node.get_node_names_and_namespaces()
for node_name, node_ns in node_names_and_ns:
Expand Down
11 changes: 7 additions & 4 deletions ros2action/ros2action/verb/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ def add_arguments(self, parser, cli_name):

def main(self, *, args):
with DirectNode(args) as node:
action_clients, action_servers = get_action_clients_and_servers(
node=node,
action_name=args.action_name,
)
try:
action_clients, action_servers = get_action_clients_and_servers(
node=node,
action_name=args.action_name,
)
except Exception as e:

This comment has been minimized.

Copy link
@dirk-thomas

dirk-thomas Apr 13, 2019

Member

I would rather only catch expected exceptions here - basically the two handle before within the function. That way in case of an unexpected exception you still get a valuable stackable.

raise RuntimeError(e)

print('Action: {}'.format(args.action_name))
print('Action clients: {}'.format(len(action_clients)))
Expand Down

0 comments on commit bbd8893

Please sign in to comment.