Skip to content

Commit

Permalink
feat: report validation errors back to sender
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Sep 7, 2023
1 parent da26ad0 commit 1eb3655
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions python/src/uagents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,18 +791,6 @@ async def _process_message_queue(self):
# get an element from the queue
schema_digest, sender, message, session = await self._message_queue.get()

# lookup the model definition
model_class: Model = self._models.get(schema_digest)
if model_class is None:
continue

# parse the received message
try:
recovered = model_class.parse_raw(message)
except ValidationError as ex:
self._logger.warning(f"Unable to parse message: {ex}")
continue

context = Context(
self._identity.address,
self._name,
Expand All @@ -822,6 +810,33 @@ async def _process_message_queue(self):
logger=self._logger,
)

# lookup the model definition
model_class: Model = self._models.get(schema_digest)
if model_class is None:
await _handle_error(
context,
sender,
ErrorMessage(
error="I do not know how to handle messages with schema digest: "
+ schema_digest
),
)
continue

# parse the received message
try:
recovered = model_class.parse_raw(message)
except ValidationError as ex:
self._logger.warning(f"Unable to parse message: {ex}")
await _handle_error(
context,
sender,
ErrorMessage(
error=f"Message does not conform to expected schema: {ex}"
),
)
continue

# attempt to find the handler
handler: MessageCallback = self._unsigned_message_handlers.get(
schema_digest
Expand Down

0 comments on commit 1eb3655

Please sign in to comment.