Skip to content

Commit f564eb0

Browse files
committed
Add exception-handling and additional logging for the connection port
1 parent 6bf6a84 commit f564eb0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

streamdeck/__main__.py

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def main(
5454
# a child logger with `logging.getLogger("streamdeck.mycomponent")`, all with the same handler/formatter configuration.
5555
configure_streamdeck_logger(name="streamdeck", plugin_uuid=plugin_uuid)
5656

57+
logger.info("Stream Deck listening to plugin UUID '%s' on port %d", plugin_uuid, port)
58+
5759
if debug_port:
5860
setup_debug_mode(debug_port)
5961

streamdeck/websocket.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ def listen(self) -> Generator[str | bytes, Any, None]:
5959
message: str | bytes = self._client.recv()
6060
yield message
6161

62-
except ConnectionClosedOK:
62+
except ConnectionClosedOK as exc:
6363
logger.debug("Connection was closed normally, stopping the client.")
64+
logger.exception(dir(exc))
6465

6566
except ConnectionClosed:
6667
logger.exception("Connection was closed with an error.")
@@ -70,7 +71,11 @@ def listen(self) -> Generator[str | bytes, Any, None]:
7071

7172
def start(self) -> None:
7273
"""Start the connection to the websocket server."""
73-
self._client = connect(uri=f"ws://localhost:{self._port}")
74+
try:
75+
self._client = connect(uri=f"ws://localhost:{self._port}")
76+
except ConnectionRefusedError:
77+
logger.exception("Failed to connect to the WebSocket server. Make sure the Stream Deck software is running.")
78+
raise
7479

7580
def stop(self) -> None:
7681
"""Close the WebSocket connection, if open."""

0 commit comments

Comments
 (0)