Refactor config system to use Pydantic validation

Refactored configuration classes to inherit from a new ValidatedConfigBase using Pydantic for robust validation and error reporting. Updated api_ada_configs.py, config.py, config_base.py, and official_configs.py to replace dataclasses with Pydantic models, add field validation, and improve error messages. This change enhances configuration reliability and developer feedback for misconfigurations. Also includes minor code cleanups and removal of unused variables in other modules.
This commit is contained in:
雅诺狐
2025-08-19 15:33:43 +08:00
parent 1b2c5393e5
commit 1405b50d5a
19 changed files with 710 additions and 1224 deletions

View File

@@ -45,7 +45,7 @@ class ScheduleItem(BaseModel):
return v
except ValueError as e:
raise ValueError(f"时间格式无效应为HH:MM-HH:MM格式: {e}")
raise ValueError(f"时间格式无效应为HH:MM-HH:MM格式: {e}") from e
@validator('activity')
def validate_activity(cls, v):
@@ -285,7 +285,7 @@ class ScheduleManager:
"""使用Pydantic验证日程数据格式和完整性"""
try:
# 尝试用Pydantic模型验证
validated_schedule = ScheduleData(schedule=schedule_data)
ScheduleData(schedule=schedule_data)
logger.info("日程数据Pydantic验证通过")
return True
except ValidationError as e: