31 lines
991 B
Python
31 lines
991 B
Python
"""动作校验错误,供后续修正节点使用"""
|
|
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, Field, ValidationError
|
|
|
|
|
|
class ActionValidationError(BaseModel):
|
|
action_index: int | None = Field(
|
|
default=None, ge=0, description="失败动作的下标,从 0 开始,整批错误为 null"
|
|
)
|
|
code: Literal[
|
|
"schema_error", "generation_error", "scope_error", "field_error", "execution_error"
|
|
]
|
|
message: str
|
|
|
|
|
|
def schema_errors(error: ValidationError) -> list[ActionValidationError]:
|
|
errors = []
|
|
for item in error.errors(include_url=False, include_input=False):
|
|
location = item["loc"]
|
|
index = location[1] if len(location) > 1 and type(location[1]) is int else None
|
|
errors.append(
|
|
ActionValidationError(
|
|
action_index=index,
|
|
code="schema_error",
|
|
message=f"{' / '.join(map(str, location))}: {item['msg']}",
|
|
)
|
|
)
|
|
return errors
|