mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-17 07:50:59 +00:00
perf: 添加JSON配置文件语法检查 (#796)
This commit is contained in:
@@ -37,7 +37,10 @@ class JSONConfigFile(file_model.ConfigFile):
|
|||||||
self.template_data = json.load(f)
|
self.template_data = json.load(f)
|
||||||
|
|
||||||
with open(self.config_file_name, "r", encoding="utf-8") as 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:
|
if completion:
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -27,6 +27,7 @@ async def make_app() -> app.Application:
|
|||||||
for stage_name in stage_order:
|
for stage_name in stage_order:
|
||||||
stage_cls = stage.preregistered_stages[stage_name]
|
stage_cls = stage.preregistered_stages[stage_name]
|
||||||
stage_inst = stage_cls()
|
stage_inst = stage_cls()
|
||||||
|
|
||||||
await stage_inst.run(ap)
|
await stage_inst.run(ap)
|
||||||
|
|
||||||
await ap.initialize()
|
await ap.initialize()
|
||||||
@@ -35,5 +36,8 @@ async def make_app() -> app.Application:
|
|||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
app_inst = await make_app()
|
try:
|
||||||
await app_inst.run()
|
app_inst = await make_app()
|
||||||
|
await app_inst.run()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"应用启动失败: {e}")
|
||||||
|
|||||||
@@ -8,16 +8,3 @@ from ...config.impls import pymodule
|
|||||||
|
|
||||||
load_python_module_config = config_mgr.load_python_module_config
|
load_python_module_config = config_mgr.load_python_module_config
|
||||||
load_json_config = config_mgr.load_json_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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user