From 55e2b5be92229d42221cd751e7f41d551f622157 Mon Sep 17 00:00:00 2001 From: Nekokatt Date: Mon, 7 Sep 2020 22:02:26 +0100 Subject: [PATCH 1/2] Fixed a logic error in websocket init logic that caused fatal exceptions to not be propagated. --- hikari/impl/shard.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hikari/impl/shard.py b/hikari/impl/shard.py index efa8bcf4c8..c7ba094609 100644 --- a/hikari/impl/shard.py +++ b/hikari/impl/shard.py @@ -247,16 +247,15 @@ async def connect( raise errors.GatewayError(f"Unexpected {type(ex).__name__}: {ex}") from ex finally: if ws.closed: - return + ws._logger.debug("ws was already closed") - if raised: + elif raised: await ws.close( code=errors.ShardCloseCode.UNEXPECTED_CONDITION, message=b"unexpected fatal client error :-(", ) - return - if not ws._closing: + elif not ws._closing: # We use a special close code here that prevents Discord # randomly invalidating our session. Undocumented behaviour is # nice like that... From 15da2495c6826a21665a38ace9f0795fecfaafca Mon Sep 17 00:00:00 2001 From: Faster Speeding Date: Mon, 7 Sep 2020 22:51:39 +0100 Subject: [PATCH 2/2] Mypy fix. This error was caused by the instance assertion being limited to the scope of the `try` section of the `try except finally` statement, with a call to ws._logger in the `finally` section not valid as the value of `ws` is now now less specific. --- hikari/impl/shard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hikari/impl/shard.py b/hikari/impl/shard.py index c7ba094609..61b0803f24 100644 --- a/hikari/impl/shard.py +++ b/hikari/impl/shard.py @@ -247,7 +247,7 @@ async def connect( raise errors.GatewayError(f"Unexpected {type(ex).__name__}: {ex}") from ex finally: if ws.closed: - ws._logger.debug("ws was already closed") + logger.debug("ws was already closed") elif raised: await ws.close(