File tree Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Expand file tree Collapse file tree 1 file changed +30
-8
lines changed Original file line number Diff line number Diff line change 1616#
1717
1818import logging
19+
1920import websockets
2021
2122from matter .testing .matter_testing import MatterBaseTest
@@ -45,14 +46,35 @@ async def send_command(self, command):
4546 2. Sends the command
4647 3. Waits for and receives the response
4748 4. Logs the connection, command, and response status
49+
50+ Raises:
51+ Exception: Re-raises any exceptions after logging them clearly
4852 """
49- async with websockets .connect (SERVER_URI ) as websocket :
50- logging .info (f"Connected to { SERVER_URI } " )
53+ try :
54+ async with websockets .connect (SERVER_URI ) as websocket :
55+ logging .info (f"Connected to { SERVER_URI } " )
56+
57+ # Send command
58+ logging .info (f"Sending command: { command } " )
59+ await websocket .send (command )
60+
61+ # Receive response
62+ await websocket .recv ()
63+ logging .info ("Received command response" )
64+
65+ except ConnectionRefusedError as e :
66+ logging .error (f"Failed to connect to WebSocket server at { SERVER_URI } : Connection refused. "
67+ f"Is the DUT WebSocket server running? Error: { e } " )
68+ raise
69+
70+ except websockets .exceptions .WebSocketException as e :
71+ logging .error (f"WebSocket error while communicating with { SERVER_URI } : { e } " )
72+ raise
5173
52- # Send command
53- logging .info (f"Sending command : { command } " )
54- await websocket . send ( command )
74+ except OSError as e :
75+ logging .error (f"Network error while connecting to { SERVER_URI } : { e } " )
76+ raise
5577
56- # Receive response
57- await websocket . recv ( )
58- logging . info ( "Received command response" )
78+ except Exception as e :
79+ logging . error ( f"Unexpected error while sending command ' { command } ' to { SERVER_URI } : { e } " )
80+ raise
You can’t perform that action at this time.
0 commit comments