Skip to content

Commit 70c497d

Browse files
committed
refactor: remove 'return Exception', use isinstance instead
1 parent caaf81a commit 70c497d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/rai/rai/node.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import functools
1717
import time
18-
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type
18+
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Type, Union
1919

2020
import rclpy
2121
import rclpy.callback_groups
@@ -331,7 +331,9 @@ def adapt_requests_to_offers(
331331

332332
return request_qos
333333

334-
def get_raw_message_from_topic(self, topic: str, timeout_sec: int = 1) -> Any:
334+
def get_raw_message_from_topic(
335+
self, topic: str, timeout_sec: int = 1
336+
) -> Union[Any, str]: # ROS 2 topic or error string
335337
self.get_logger().debug(f"Getting msg from topic: {topic}")
336338
if topic in self.state_subscribers and topic in self.robot_state:
337339
self.get_logger().debug("Returning cached message")
@@ -366,7 +368,7 @@ def get_raw_message_from_topic(self, topic: str, timeout_sec: int = 1) -> Any:
366368
f"No message received in {timeout_sec} seconds from topic {topic}"
367369
)
368370
self.get_logger().error(error)
369-
return Exception(error)
371+
return error
370372

371373
def get_msg_type(self, topic: str, n_tries: int = 5) -> Any:
372374
"""Sometimes node fails to do full discovery, therefore we need to retry"""

tests/messages/test_transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_transport(qos_profile: str):
103103
try:
104104
for topic in topics:
105105
output = rai_base_node.get_raw_message_from_topic(topic, timeout_sec=5.0)
106-
assert not isinstance(output, Exception), f"Exception: {output}"
106+
assert not isinstance(output, str), "No message received"
107107
finally:
108108
executor.shutdown()
109109
publisher.destroy_node()

0 commit comments

Comments
 (0)