-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enforce correct message type is passed to various API #317
Conversation
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
9002f74
to
d49d33b
Compare
future = cli.call_async(GetParameters.Request()) | ||
executor = rclpy.executors.SingleThreadedExecutor(context=self.context) | ||
with self.assertRaises(TypeError): | ||
rclpy.spin_until_future_complete(self.node, future, executor=executor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this traceback look like? I would have expected the exception to be swallowed here:
Lines 212 to 213 in afc4cd4
except Exception as e: | |
self.set_exception(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output of the test without the with self.assertRaises(TypeError):
:
rclpy/__init__.py:204: in spin_until_future_complete
executor.spin_until_future_complete(future, timeout_sec)
rclpy/executors.py:271: in spin_until_future_complete
self.spin_once(timeout_sec=timeout_sec)
rclpy/executors.py:628: in spin_once
raise handler.exception()
rclpy/task.py:206: in __call__
self._handler.send(None)
rclpy/executors.py:382: in handler
await call_coroutine(entity, arg)
rclpy/executors.py:337: in _execute_service
srv.send_response(response, header)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <rclpy.service.Service object at 0x7f549dd3bc88>
response = 'different response type'
header = <capsule object "rmw_request_id_t" at 0x7f549dd3c4e0>
def send_response(self, response: SrvTypeResponse, header) -> None:
"""
Send a service response.
:param response: The service response.
:param header: Capsule pointing to the service header from the original request.
:raises: TypeError if the type of the passed response isn't an instance
of the Response type of the provided service when the service was
constructed.
"""
if not isinstance(response, self.srv_type.Response):
> raise TypeError()
E TypeError
rclpy/service.py:79: TypeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh I didn't know about
rclpy/rclpy/rclpy/executors.py
Lines 627 to 628 in afc4cd4
if handler.exception() is not None: | |
raise handler.exception() |
Closes #314.
The PR contains two commits:
TypeError
to be raised. CI with these tests failing: ( intentionally failing tests)TypeError
in case it doesn't match the expected type: