From a536dde677c7b8e61ad235efa7a41d1f415d0c8b Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Sat, 17 Feb 2024 11:31:37 +0100 Subject: [PATCH] Add exception-catchers that point out exactly which game or channel causes a crash --- channel.py | 9 ++++++--- twitch.py | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/channel.py b/channel.py index 68e88e6..41ed204 100644 --- a/channel.py +++ b/channel.py @@ -244,9 +244,12 @@ class Channel: return URLType(match.group(1)) async def get_stream(self) -> Stream | None: - response: JsonType = await self._twitch.gql_request( - GQL_OPERATIONS["GetStreamInfo"].with_variables({"channel": self._login}) - ) + try: + response: JsonType = await self._twitch.gql_request( + GQL_OPERATIONS["GetStreamInfo"].with_variables({"channel": self._login}) + ) + except MinerException as exc: + raise MinerException(f"Channel: {self._login}") from exc stream_data: JsonType | None = response["data"]["user"] if not stream_data: return None diff --git a/twitch.py b/twitch.py index ee50c5a..89aed30 100644 --- a/twitch.py +++ b/twitch.py @@ -1710,16 +1710,19 @@ class Twitch: return None async def get_live_streams(self, game: Game, *, limit: int = 30) -> list[Channel]: - response = await self.gql_request( - GQL_OPERATIONS["GameDirectory"].with_variables({ - "limit": limit, - "slug": game.slug, - "options": { - "includeRestricted": ["SUB_ONLY_LIVE"], - "systemFilters": ["DROPS_ENABLED"], - }, - }) - ) + try: + response = await self.gql_request( + GQL_OPERATIONS["GameDirectory"].with_variables({ + "limit": limit, + "slug": game.slug, + "options": { + "includeRestricted": ["SUB_ONLY_LIVE"], + "systemFilters": ["DROPS_ENABLED"], + }, + }) + ) + except MinerException as exc: + raise MinerException(f"Game: {game.slug}") from exc if "game" in response["data"]: return [ Channel.from_directory(self, stream_channel_data["node"], drops_enabled=True)