From d68a6c28ba93df4f9bca6cb5a4bde4da09adfa0e Mon Sep 17 00:00:00 2001 From: Justin Schuh Date: Sat, 8 Apr 2023 19:34:32 -0700 Subject: [PATCH] webhooks: Log json encoding errors Signed-off-by: Justin Schuh --- klippy/webhooks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/klippy/webhooks.py b/klippy/webhooks.py index 43ff9a91..9188a4f7 100644 --- a/klippy/webhooks.py +++ b/klippy/webhooks.py @@ -268,8 +268,14 @@ class ClientConnection: self.send(result) def send(self, data): - jmsg = json.dumps(data, separators=(',', ':')) - self.send_buffer += jmsg.encode() + b"\x03" + try: + jmsg = json.dumps(data, separators=(',', ':')) + self.send_buffer += jmsg.encode() + b"\x03" + except (TypeError, ValueError) as e: + msg = ("json encoding error: %s" % (str(e),)) + logging.exception(msg) + self.printer.invoke_shutdown(msg) + return if not self.is_blocking: self._do_send()