From 38d4f8acf550c5bf140827ec6aaa00c47627ef7d Mon Sep 17 00:00:00 2001 From: Alaeddine Mesbahi Date: Fri, 9 Feb 2024 18:40:17 +0100 Subject: [PATCH] Handle JSON error. --- pychrome/__init__.py | 2 +- pychrome/tab.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pychrome/__init__.py b/pychrome/__init__.py index 0e8ee32..db2611e 100644 --- a/pychrome/__init__.py +++ b/pychrome/__init__.py @@ -7,4 +7,4 @@ from .tab import * from .exceptions import * -__version__ = "0.2.5" +__version__ = "0.2.6" diff --git a/pychrome/tab.py b/pychrome/tab.py index a2d4338..598d179 100644 --- a/pychrome/tab.py +++ b/pychrome/tab.py @@ -124,7 +124,12 @@ def _recv_loop(self): if self.debug: # pragma: no cover print("< RECV %s" % message_json) - message = json.loads(message_json) + try: + message = json.loads(message_json) + except json.decoder.JSONDecodeError: + logger.error("Error decoding message: `%s`", message_json, exc_info=True) + return + except websocket.WebSocketTimeoutException: continue except (websocket.WebSocketException, OSError):