File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626from functools import lru_cache
2727
2828import yaml
29- from pydantic import model_validator , BaseModel
29+ from pydantic import model_validator , BaseModel , ValidationError
3030
3131logger = logging .getLogger (__name__ )
3232
@@ -88,14 +88,13 @@ def from_yaml(cls, yaml_file: str = "config.yaml"):
8888 # 使用 model_validate 创建实例
8989 try :
9090 return cls .model_validate (config_data )
91- except Exception as e : # pylint: disable=broad-except
92- logger .warning ("配置验证失败: %s, Exception: %s" , str (e ), type (e ).__name__ )
93- logger .warning ("使用默认配置" )
94-
95- # 更新基本配置
96- for key , value in config_data .items ():
97- if key != "WEBHOOK" and hasattr (config , key ):
98- setattr (config , key , value )
91+ except yaml .YAMLError as e :
92+ logger .error ("YAML配置加载失败: %s" , e )
93+ raise
94+ except ValidationError as e :
95+ logger .error ("Pydantic配置验证失败: %s" , e )
96+ raise
97+
9998 else :
10099 logger .warning ("警告:配置文件 %s 不存在,使用默认配置" , config_path )
101100
You can’t perform that action at this time.
0 commit comments