1
0
mirror of https://github.com/FreeOpcUa/opcua-asyncio synced 2025-10-29 17:07:18 +08:00

Merge pull request #2 from Ai-Ops-Inc/csmith/updating-message-error-handling

Updating message error handling
This commit is contained in:
Connor Smith 2025-09-18 16:03:22 -05:00 committed by GitHub
commit c8f01cad65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -183,10 +183,13 @@ class UASocketProtocol(asyncio.Protocol):
await self.pre_request_hook()
try:
data = await wait_for(self._send_request(request, timeout, message_type), timeout if timeout else None)
except UaError as ex:
# Recieved UA error, re-raise it to the caller
raise ex
except Exception as ex:
if self.state != self.OPEN:
raise ConnectionError("Connection is closed") from None
raise UaError("Failed to send request to OPC UA server") from ex
raise Exception("Unhandled exception while sending request to OPC UA server") from ex
self.check_answer(data, f" in response to {request.__class__.__name__}")
return data

View File

@ -800,11 +800,11 @@ async def test_message_limits_fail_write(restore_transport_limits_server: Server
n = await server.nodes.objects.add_variable(1, "MyLimitVariable", test_string)
await n.set_writable(True)
client = Client(server.endpoint.geturl())
# This should trigger a timeout error because the message is to large
# This should trigger a UA error because the message is too large
async with client:
n = client.get_node(n.nodeid)
await n.read_value()
with pytest.raises(ConnectionError):
with pytest.raises(ua.uaerrors.BadRequestTooLarge):
await n.write_value(test_string, ua.VariantType.ByteString)
@ -818,11 +818,11 @@ async def test_message_limits_fail_read(restore_transport_limits_server: Server)
n = await server.nodes.objects.add_variable(1, "MyLimitVariable", test_string)
await n.set_writable(True)
client = Client(server.endpoint.geturl())
# This should trigger a connection error because the message is to large
# This should trigger a UA error because the message is too large
async with client:
n = client.get_node(n.nodeid)
await n.write_value(test_string, ua.VariantType.ByteString)
with pytest.raises(ConnectionError):
with pytest.raises(ua.uaerrors.BadRequestTooLarge):
await n.read_value()