Skip to content

Commit

Permalink
fix: catch parser errors (#1680)
Browse files Browse the repository at this point in the history
* fix: catch Parser & Decoder errors in middlewares

* chore: bump version

* lint: fix codespell
  • Loading branch information
Lancetnik authored Aug 13, 2024
1 parent 5965b36 commit 4bf70ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion faststream/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Simple and fast framework to create message brokers based microservices."""

__version__ = "0.5.17"
__version__ = "0.5.18"

SERVICE_NAME = f"faststream-{__version__}"
19 changes: 16 additions & 3 deletions faststream/broker/subscriber/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,17 @@ async def process_message(self, msg: MsgType) -> Any:
await middleware.__aenter__()

cache: Dict[Any, Any] = {}
parsing_error: Optional[Exception] = None
for h in self.calls:
if (message := await h.is_suitable(msg, cache)) is not None:
try:
message = await h.is_suitable(msg, cache)
except Exception as e:
parsing_error = e
break

if message is not None:
# Acknowledgement scope
# TODO: move it to scope enter at `retry` option deprecation
await stack.enter_async_context(
self.watcher(
message,
Expand Down Expand Up @@ -377,11 +385,16 @@ async def process_message(self, msg: MsgType) -> Any:

return result_msg.body

# Suitable handler is not founded
# Suitable handler was not found or
# parsing/decoding exception occurred
for m in middlewares:
stack.push_async_exit(m.__aexit__)

raise AssertionError(f"There is no suitable handler for {msg=}")
if parsing_error:
raise parsing_error

else:
raise AssertionError(f"There is no suitable handler for {msg=}")

return None

Expand Down

0 comments on commit 4bf70ad

Please sign in to comment.