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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user