From 927ba0e04c1298618cab8b1cbcbc2fd35f1a90bd Mon Sep 17 00:00:00 2001 From: echoyang7 <50300391+echoyang7@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:20:34 +0800 Subject: [PATCH] ad d try/catch when operate personal_conf,bugfix (#799) Co-authored-by: yangfan100 --- lyrebird/config/__init__.py | 15 +++++++++++---- lyrebird/version.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lyrebird/config/__init__.py b/lyrebird/config/__init__.py index c64507f0e..d95f8f601 100644 --- a/lyrebird/config/__init__.py +++ b/lyrebird/config/__init__.py @@ -244,12 +244,19 @@ def update_personal_config(self, config_dict: dict): self.write_personal_config() def read_personal_config(self): - with codecs.open(self.personal_conf_file, 'r', 'utf-8') as f: - return json.load(f) + try: + with codecs.open(self.personal_conf_file, 'r', 'utf-8') as f: + return json.load(f) + except json.JSONDecodeError: + logger.error(f'Failed to parse personal config file {self.personal_conf_file}!') + return personal_config_template def write_personal_config(self): - with codecs.open(self.personal_conf_file, 'w', 'utf-8') as f: - f.write(json.dumps(self.personal_config, indent=4, ensure_ascii=False)) + try: + with codecs.open(self.personal_conf_file, 'w', 'utf-8') as f: + f.write(json.dumps(self.personal_config, indent=4, ensure_ascii=False)) + except Exception as e: + logger.error(f'Failed to write personal config: {e}') class Config: diff --git a/lyrebird/version.py b/lyrebird/version.py index c8a54f5af..05e3ca52f 100644 --- a/lyrebird/version.py +++ b/lyrebird/version.py @@ -1,3 +1,3 @@ -IVERSION = (2, 20, 0) +IVERSION = (2, 20, 1) VERSION = ".".join(str(i) for i in IVERSION) LYREBIRD = "Lyrebird " + VERSION