Skip to content

Commit

Permalink
refactor: remove 'return Exception', use isinstance instead
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejmajek committed Jan 3, 2025
1 parent caaf81a commit 70c497d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/rai/rai/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import functools
import time
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union

import rclpy
import rclpy.callback_groups
Expand Down Expand Up @@ -331,7 +331,9 @@ def adapt_requests_to_offers(

return request_qos

def get_raw_message_from_topic(self, topic: str, timeout_sec: int = 1) -> Any:
def get_raw_message_from_topic(
self, topic: str, timeout_sec: int = 1
) -> Union[Any, str]: # ROS 2 topic or error string
self.get_logger().debug(f"Getting msg from topic: {topic}")
if topic in self.state_subscribers and topic in self.robot_state:
self.get_logger().debug("Returning cached message")
Expand Down Expand Up @@ -366,7 +368,7 @@ def get_raw_message_from_topic(self, topic: str, timeout_sec: int = 1) -> Any:
f"No message received in {timeout_sec} seconds from topic {topic}"
)
self.get_logger().error(error)
return Exception(error)
return error

def get_msg_type(self, topic: str, n_tries: int = 5) -> Any:
"""Sometimes node fails to do full discovery, therefore we need to retry"""
Expand Down
2 changes: 1 addition & 1 deletion tests/messages/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_transport(qos_profile: str):
try:
for topic in topics:
output = rai_base_node.get_raw_message_from_topic(topic, timeout_sec=5.0)
assert not isinstance(output, Exception), f"Exception: {output}"
assert not isinstance(output, str), "No message received"
finally:
executor.shutdown()
publisher.destroy_node()
Expand Down

0 comments on commit 70c497d

Please sign in to comment.