Skip to content

Commit 1061898

Browse files
committed
fix: add warning if websocket connection isnt open
1 parent 7b3c139 commit 1061898

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

hivemind_bus_client/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ def on_close(self, *args):
236236
def wait_for_handshake(self, timeout=5):
237237
self.handshake_event.wait(timeout=timeout)
238238
if not self.handshake_event.is_set():
239-
self.protocol.start_handshake()
239+
if self.connected_event.is_set():
240+
self.protocol.start_handshake()
241+
else:
242+
LOG.warning("Can't start handshake because websocket connection is not yet open...")
243+
self.connected_event.wait(timeout=timeout)
240244
self.wait_for_handshake()
241245

242246
@staticmethod
@@ -353,12 +357,12 @@ def emit(self, message: Union[MycroftMessage, HiveMessage],
353357
message = HiveMessage(msg_type=HiveMessageType.BUS,
354358
payload=message)
355359
if not self.connected_event.is_set():
356-
LOG.warning("hivemind connection not ready")
360+
LOG.warning(f"hivemind connection not ready: {message.serialize()}")
357361
if not self.connected_event.wait(10):
358362
if not self.started_running:
359363
raise ValueError('You must execute run_forever() '
360364
'before emitting messages')
361-
self.connected_event.wait()
365+
raise RuntimeError(f"Can not send messages before opening the websocket connection. Failed to emit : {message.serialize()}")
362366

363367
try:
364368
# auto inject context for proper routing, this is confusing for

0 commit comments

Comments
 (0)