Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid logging graceful disconnect as error #987

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pychromecast/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ChromecastConnectionError(PyChromecastError):
"""When a connection error occurs within PyChromecast."""


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


class PyChromecastStopped(PyChromecastError):
"""Raised when a command is invoked while the Chromecast's socket_client
is stopped.
Expand Down
12 changes: 11 additions & 1 deletion pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from .dial import get_host_from_service
from .error import (
ChromecastConnectionError,
ChromecastConnectionClosed,
ControllerNotRegistered,
NotConnected,
PyChromecastStopped,
Expand Down Expand Up @@ -619,6 +620,15 @@ def _run_once(self) -> int:
if self.stop.is_set():
return 1
raise
except ChromecastConnectionClosed as exc:
self._force_recon = True
self.logger.debug(
"[%s(%s):%s] %s",
self.fn or "",
self.host,
self.port,
exc,
)
except socket.error as exc:
self._force_recon = True
self.logger.error(
Expand Down Expand Up @@ -817,7 +827,7 @@ def _read_bytes_from_socket(self, msglen: int) -> bytes:
try:
chunk = self.socket.recv(min(msglen - bytes_recd, 2048))
if chunk == b"":
raise socket.error("socket connection broken")
raise ChromecastConnectionClosed("Connection was closed by remote")
chunks.append(chunk)
bytes_recd += len(chunk)
except TimeoutError:
Expand Down