aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-07-24 08:05:23 -0400
committerRapptz <[email protected]>2020-07-25 09:59:40 -0400
commita42bebe5812dabccee574155d3a2bbbba9823bf8 (patch)
treeffc079acf128e54b36bc4e1a8509b01fbd8be3e4
parentUse a subclass rather than monkey-patching for the websocket (diff)
downloaddiscord.py-a42bebe5812dabccee574155d3a2bbbba9823bf8.tar.xz
discord.py-a42bebe5812dabccee574155d3a2bbbba9823bf8.zip
Propagate exceptions when an unhandled error happens
-rw-r--r--discord/shard.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/discord/shard.py b/discord/shard.py
index 7659e5ec..e3835187 100644
--- a/discord/shard.py
+++ b/discord/shard.py
@@ -45,6 +45,7 @@ class EventType:
reconnect = 1
resume = 2
identify = 3
+ terminate = 4
class EventItem:
__slots__ = ('type', 'shard', 'error')
@@ -139,6 +140,11 @@ class Shard:
except self._handled_exceptions as e:
await self._handle_disconnect(e)
break
+ except asyncio.CancelledError:
+ break
+ except Exception as e:
+ self._queue.put_nowait(EventItem(EventType.terminate, self, e))
+ break
async def reidentify(self, exc):
self._cancel_task()
@@ -151,6 +157,10 @@ class Shard:
self.ws = await asyncio.wait_for(coro, timeout=60.0)
except self._handled_exceptions as e:
await self._handle_disconnect(e)
+ except asyncio.CancelledError:
+ return
+ except Exception as e:
+ self._queue.put_nowait(EventItem(EventType.terminate, self, e))
else:
self.launch()
@@ -161,6 +171,10 @@ class Shard:
self.ws = await asyncio.wait_for(coro, timeout=60.0)
except self._handled_exceptions as e:
await self._handle_disconnect(e)
+ except asyncio.CancelledError:
+ return
+ except Exception as e:
+ self._queue.put_nowait(EventItem(EventType.terminate, self, e))
else:
self.launch()
@@ -312,6 +326,9 @@ class AutoShardedClient(Client):
await item.shard.reidentify(item.error)
elif item.type == EventType.reconnect:
await item.shard.reconnect()
+ elif item.type == EventType.terminate:
+ await self.close()
+ raise item.error
async def close(self):
"""|coro|