Skip to content

Commit 19526cb

Browse files
committed
Improve error message for encoding of field annotations.
1 parent a65ce30 commit 19526cb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

python/cocoindex/typing.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,17 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
137137
dataclass_type=dataclass_type, attrs=attrs, nullable=nullable)
138138

139139
def _encode_fields_schema(dataclass_type: type) -> list[dict[str, Any]]:
140-
return [{ 'name': field.name,
141-
**encode_enriched_type_info(analyze_type_info(field.type))
142-
} for field in dataclasses.fields(dataclass_type)]
140+
result = []
141+
for field in dataclasses.fields(dataclass_type):
142+
try:
143+
type_info = encode_enriched_type_info(analyze_type_info(field.type))
144+
except ValueError as e:
145+
e.add_note(f"Failed to encode annotation for field - "
146+
f"{dataclass_type.__name__}.{field.name}: {field.type}")
147+
raise
148+
type_info['name'] = field.name
149+
result.append(type_info)
150+
return result
143151

144152
def _encode_type(type_info: AnalyzedTypeInfo) -> dict[str, Any]:
145153
encoded_type: dict[str, Any] = { 'kind': type_info.kind }

0 commit comments

Comments
 (0)