From 1b6bc86e7683e2c674aea4053894ed44bfb0293f Mon Sep 17 00:00:00 2001 From: taizan-hokouto <55448286+taizan-hokuto@users.noreply.github.com> Date: Sun, 15 Nov 2020 23:49:36 +0900 Subject: [PATCH] Fix handling exception --- pytchat/core/pytchat.py | 7 ++----- pytchat/core_async/livechat.py | 4 ++-- pytchat/core_multithread/livechat.py | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pytchat/core/pytchat.py b/pytchat/core/pytchat.py index f3a8172..004a3a5 100644 --- a/pytchat/core/pytchat.py +++ b/pytchat/core/pytchat.py @@ -118,13 +118,10 @@ class PytchatCore: except exceptions.ChatParseException as e: self._logger.debug(f"[{self._video_id}]{str(e)}") self._raise_exception(e) - except (TypeError, json.JSONDecodeError) as e: + except Exception as e: self._logger.error(f"{traceback.format_exc(limit=-1)}") self._raise_exception(e) - self._logger.debug(f"[{self._video_id}]finished fetching chat.") - self._raise_exception(exceptions.ChatDataFinished) - def _get_contents(self, continuation, client, headers): '''Get 'continuationContents' from livechat json. If contents is None at first fetching, @@ -201,7 +198,7 @@ class PytchatCore: raise self._exception_holder def _raise_exception(self, exception: Exception = None): - self._is_alive = False + self.terminate() if self._hold_exception is False: raise exception self._exception_holder = exception diff --git a/pytchat/core_async/livechat.py b/pytchat/core_async/livechat.py index 5dccb4c..1c0231e 100644 --- a/pytchat/core_async/livechat.py +++ b/pytchat/core_async/livechat.py @@ -186,12 +186,12 @@ class LiveChatAsync: except exceptions.ChatParseException as e: self._logger.debug(f"[{self._video_id}]{str(e)}") raise - except (TypeError, json.JSONDecodeError): + except Exception: self._logger.error(f"{traceback.format_exc(limit = -1)}") raise self._logger.debug(f"[{self._video_id}] finished fetching chat.") - raise exceptions.ChatDataFinished + async def _check_pause(self, continuation): if self._pauser.empty(): diff --git a/pytchat/core_multithread/livechat.py b/pytchat/core_multithread/livechat.py index 8e025c2..3eb5184 100644 --- a/pytchat/core_multithread/livechat.py +++ b/pytchat/core_multithread/livechat.py @@ -179,12 +179,12 @@ class LiveChat: except exceptions.ChatParseException as e: self._logger.debug(f"[{self._video_id}]{str(e)}") raise - except (TypeError, json.JSONDecodeError): + except Exception: self._logger.error(f"{traceback.format_exc(limit=-1)}") raise self._logger.debug(f"[{self._video_id}] finished fetching chat.") - raise exceptions.ChatDataFinished + def _check_pause(self, continuation): if self._pauser.empty():