Skip to content

Commit c70c8d4

Browse files
authored
fix produce proto type + error (#142)
1 parent 38fdd98 commit c70c8d4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

memphis/producer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ async def validate_msg(self, message):
5252
message = str(msg.loc.source.body)
5353
message = message.encode("utf-8")
5454
return message
55+
elif hasattr(message, "SerializeToString"):
56+
msgToSend = message.SerializeToString()
57+
return msgToSend
5558
elif not isinstance(message, bytearray) and not isinstance(message, dict):
5659
raise MemphisSchemaError("Unsupported message type")
5760
else:
@@ -78,6 +81,13 @@ def validate_protobuf(self, message):
7881
msgToSend = message.SerializeToString()
7982
proto_msg.ParseFromString(msgToSend)
8083
proto_msg.SerializeToString()
84+
try:
85+
proto_msg.ParseFromString(msgToSend)
86+
proto_msg.SerializeToString()
87+
except Exception as e:
88+
if "parsing message" in str(e):
89+
e = "Error parsing protobuf message"
90+
raise MemphisSchemaError(str(e))
8191
return msgToSend
8292

8393
else:

0 commit comments

Comments
 (0)