Skip to content

Commit

Permalink
Raise exception in ExceptionMiddleware if no exc handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimond committed May 25, 2022
1 parent fd6a5fb commit a20b20d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
7 changes: 1 addition & 6 deletions pybotx/bot/middlewares/exception_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ async def dispatch(
except Exception as message_handler_exc:
exception_handler = self._get_exception_handler(message_handler_exc)
if exception_handler is None:
exc_name = type(message_handler_exc).__name__
logger.exception(
f"Uncaught exception {exc_name}:",
message_handler_exc,
)
return
raise message_handler_exc

try: # noqa: WPS505
await exception_handler(message, bot, message_handler_exc)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pybotx"
version = "0.42.1"
version = "0.43.0"
description = "A python library for interacting with eXpress BotX API"
authors = [
"Sidnev Nikolay <[email protected]>",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_exception_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ async def handler(message: IncomingMessage, bot: Bot) -> None:

# - Act -
async with lifespan_wrapper(built_bot) as bot:
bot.async_execute_bot_command(user_command)
with pytest.raises(ValueError) as exc:
await bot.async_execute_bot_command(user_command)

# - Assert -
assert "Uncaught exception ValueError" in loguru_caplog.text
assert "Testing exception middleware" in loguru_caplog.text
assert "Testing exception middleware" in str(exc.value)


async def test__exception_middleware__error_in_handler_logs(
Expand Down

0 comments on commit a20b20d

Please sign in to comment.