From f81808d239bce9c658f95505a31f5b4885c59e23 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Wed, 29 May 2024 21:11:21 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=B7=BB=E5=8A=A0JSON=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AF=AD=E6=B3=95=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=20(#796)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/config/impls/json.py | 5 ++++- pkg/core/boot.py | 8 ++++++-- pkg/core/bootutils/config.py | 13 ------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pkg/config/impls/json.py b/pkg/config/impls/json.py index 362bc78a..e414e451 100644 --- a/pkg/config/impls/json.py +++ b/pkg/config/impls/json.py @@ -37,7 +37,10 @@ class JSONConfigFile(file_model.ConfigFile): self.template_data = json.load(f) with open(self.config_file_name, "r", encoding="utf-8") as f: - cfg = json.load(f) + try: + cfg = json.load(f) + except json.JSONDecodeError as e: + raise Exception(f"配置文件 {self.config_file_name} 语法错误: {e}") if completion: diff --git a/pkg/core/boot.py b/pkg/core/boot.py index 081a2f84..7cf0b420 100644 --- a/pkg/core/boot.py +++ b/pkg/core/boot.py @@ -27,6 +27,7 @@ async def make_app() -> app.Application: for stage_name in stage_order: stage_cls = stage.preregistered_stages[stage_name] stage_inst = stage_cls() + await stage_inst.run(ap) await ap.initialize() @@ -35,5 +36,8 @@ async def make_app() -> app.Application: async def main(): - app_inst = await make_app() - await app_inst.run() + try: + app_inst = await make_app() + await app_inst.run() + except Exception as e: + print(f"应用启动失败: {e}") diff --git a/pkg/core/bootutils/config.py b/pkg/core/bootutils/config.py index 0addff08..940a6132 100644 --- a/pkg/core/bootutils/config.py +++ b/pkg/core/bootutils/config.py @@ -8,16 +8,3 @@ from ...config.impls import pymodule load_python_module_config = config_mgr.load_python_module_config load_json_config = config_mgr.load_json_config - - -async def override_config_manager(cfg_mgr: config_mgr.ConfigManager) -> list[str]: - override_json = json.load(open("override.json", "r", encoding="utf-8")) - overrided = [] - - config = cfg_mgr.data - for key in override_json: - if key in config: - config[key] = override_json[key] - overrided.append(key) - - return overrided