Skip to content

Commit bb55840

Browse files
committed
Avoid logging graceful disconnect as error
The chromecasts restart each night, and seem to generally do this by doing a socket shutdown of write leading to a EOF received by clients. No need to log this as an error
1 parent 97446b7 commit bb55840

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pychromecast/error.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class PyChromecastError(Exception):
1010
class ChromecastConnectionError(PyChromecastError):
1111
"""When a connection error occurs within PyChromecast."""
1212

13+
class ChromecastConnectionClosed(PyChromecastError):
14+
"""When a connection was closed by remote device."""
1315

1416
class PyChromecastStopped(PyChromecastError):
1517
"""Raised when a command is invoked while the Chromecast's socket_client

pychromecast/socket_client.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from .dial import get_host_from_service
3434
from .error import (
3535
ChromecastConnectionError,
36+
ChromecastConnectionClosed,
3637
ControllerNotRegistered,
3738
NotConnected,
3839
PyChromecastStopped,
@@ -619,6 +620,15 @@ def _run_once(self) -> int:
619620
if self.stop.is_set():
620621
return 1
621622
raise
623+
except ChromecastConnectionClosed as exc:
624+
self._force_recon = True
625+
self.logger.debug(
626+
"[%s(%s):%s] %s",
627+
self.fn or "",
628+
self.host,
629+
self.port,
630+
exc,
631+
)
622632
except socket.error as exc:
623633
self._force_recon = True
624634
self.logger.error(
@@ -817,7 +827,7 @@ def _read_bytes_from_socket(self, msglen: int) -> bytes:
817827
try:
818828
chunk = self.socket.recv(min(msglen - bytes_recd, 2048))
819829
if chunk == b"":
820-
raise socket.error("socket connection broken")
830+
raise ChromecastConnectionClosed("Connection was closed by remote")
821831
chunks.append(chunk)
822832
bytes_recd += len(chunk)
823833
except TimeoutError:

0 commit comments

Comments
 (0)