From bf7469805898b7e92f6508e7f8d39f731f2b33a1 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 1 Nov 2023 02:38:23 +0100 Subject: [PATCH] Added error handling to config reload --- sbapp/sideband/core.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 3891351..c8a8748 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -612,11 +612,16 @@ class SidebandCore(): def __reload_config(self): RNS.log("Reloading Sideband configuration... "+str(self.config_path), RNS.LOG_DEBUG) - config_file = open(self.config_path, "rb") - self.config = msgpack.unpackb(config_file.read()) - config_file.close() + with open(self.config_path, "rb") as config_file: + config_data = config_file.read() - self.update_active_lxmf_propagation_node() + try: + unpacked_config = msgpack.unpackb(config_data) + if unpacked_config != None and len(unpacked_config) != 0: + self.config = unpacked_config + self.update_active_lxmf_propagation_node() + except Exception as e: + RNS.log("Error while reloading configuration: "+str(e), RNS.LOG_ERROR) def __save_config(self): RNS.log("Saving Sideband configuration...", RNS.LOG_DEBUG)