From 5071343269d390c095c7e7846c4b1b3a97daab3c Mon Sep 17 00:00:00 2001 From: lukken <lukken@astron.nl> Date: Tue, 22 Feb 2022 14:26:45 +0000 Subject: [PATCH] L2SS-627: Clarify error types for opcua client --- .../tangostationcontrol/clients/opcua_client.py | 3 +-- .../default/client/test_opcua_client_against_server.py | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tangostationcontrol/tangostationcontrol/clients/opcua_client.py b/tangostationcontrol/tangostationcontrol/clients/opcua_client.py index 813ec9908..073933ad7 100644 --- a/tangostationcontrol/tangostationcontrol/clients/opcua_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/opcua_client.py @@ -216,11 +216,10 @@ class OPCUAConnection(AsyncCommClient): node = await self.get_node(method_path[:-1]) result = await node.call_method(method_path[-1], *args) except Exception as e: - raise Exception(f"Calling method {method_path} failed") from e + raise RuntimeError(f"Calling method {method_path} failed") from e return result - def call_method(self, method_path, *args): return asyncio.run_coroutine_threadsafe(self._call_method(method_path, *args), self.event_loop).result() diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/client/test_opcua_client_against_server.py b/tangostationcontrol/tangostationcontrol/integration_test/default/client/test_opcua_client_against_server.py index 8a1d035f6..3ce57a0ae 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/client/test_opcua_client_against_server.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/client/test_opcua_client_against_server.py @@ -45,7 +45,9 @@ class TestClientServer(base.IntegrationAsyncTestCase): @asyncua.uamethod def throws(parent): - raise RuntimeError("Expected test exception") + """This is not the exception raised by the opcua_client since it will + be caught""" + raise ArithmeticError("Expected test exception") multiply_method = await obj.add_method(idx, "multiply", multiply, [asyncua.ua.VariantType.Double, asyncua.ua.VariantType.Int64], [asyncua.ua.VariantType.Double]) procedure_method = await obj.add_method(idx, "procedure", procedure, [], []) @@ -62,7 +64,9 @@ class TestClientServer(base.IntegrationAsyncTestCase): await self.server.stop() def fault_func(self): - raise RuntimeError("FAULT") + """This is not the exception raised by the opcua_client since it will + be caught""" + raise ArithmeticError("FAULT") async def test_opcua_connection(self): await self.setup_server(14840) -- GitLab