Skip to content

Commit

Permalink
protobuf: better error handling if type and type_name are missing
Browse files Browse the repository at this point in the history
Raise InvalidSchema instead of using assert.
  • Loading branch information
juha-aiven committed Feb 8, 2024
1 parent 5086e27 commit a713162
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion karapace/protobuf/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from __future__ import annotations

from karapace.errors import InvalidSchema
from karapace.protobuf.enum_constant_element import EnumConstantElement
from karapace.protobuf.enum_element import EnumElement
from karapace.protobuf.field import Field
Expand Down Expand Up @@ -53,7 +54,8 @@ def _deserialize_field(field: Any) -> FieldElement:
if field.HasField("type_name"):
element_type = field.type_name
else:
assert field.HasField("type")
if not field.HasField("type"):
raise InvalidSchema(f"field {field.name} has no type_name nor type")
if field.type not in _TYPE_MAP:
raise NotImplementedError(f"Unsupported field type {field.type}")
element_type = _TYPE_MAP[field.type]
Expand Down

0 comments on commit a713162

Please sign in to comment.