Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to properly propagate client exceptions: Task exception was never retrieved #2237

Closed
0x5c opened this issue Jun 20, 2019 · 2 comments

Comments

@0x5c
Copy link

commented Jun 20, 2019

Summary

Client exceptions are never propagated out of .run().
Cause is seemingly a failure to take the steps to ensure propagation, as the asyncio documentation suggests.

Reproduction Steps

  1. Use the latest discord.py version (freshly installed).
  2. Use python 3.7.3 (Versions 3.6.?, 3.7.1, and 3.8.? were shown in the discord thread to exhibit the same issue).
  3. This code:
import discord

try:
    discord.Client().run("borked token")
except:
    print("Caught!")

Expected Results

Exception is propagated to user code, where it can be caught.

Actual Results

Exception is lost in library code, and it is [seemingly] not propagated through the loop(?).

(botenv) root@GLaDOS:/mnt/c/dev/bots/asyncdemo# python -V; pip -V
Python 3.7.3
pip 19.1.1 from /mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/pip (python 3.7)
(botenv) root@GLaDOS:/mnt/c/dev/bots/asyncdemo# cat main.py
#!/usr/bin/env python3

import discord

try:
    discord.Client().run("borked token")
except:
    print("Caught!")
(botenv) root@GLaDOS:/mnt/c/dev/bots/asyncdemo# ./main.py
Task exception was never retrieved
future: <Task finished coro=<Client.run.<locals>.runner() done, defined at /mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/client.py:577> exception=LoginFailure('Improper token has been passed.')>
Traceback (most recent call last):
  File "/mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/http.py", line 258, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/http.py", line 222, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 401 UNAUTHORIZED (error code: 0): 401: Unauthorized

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/client.py", line 579, in runner
    await self.start(*args, **kwargs)
  File "/mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/client.py", line 542, in start
    await self.login(*args, bot=bot)
  File "/mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/client.py", line 400, in login
    await self.http.static_login(token, bot=bot)
  File "/mnt/c/dev/bots/asyncdemo/botenv/lib/python3.7/site-packages/discord/http.py", line 262, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.

Checklist

  • I have searched the open issues for duplicates.
    --> Malformed and poorly-researched issue #1420 shows up.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible. N/A

System Information

  • Python v3.7.3-final
  • discord.py v1.2.2-final
  • aiohttp v3.5.4
  • websockets v6.0
  • system info: Linux 4.4.0-17763-Microsoft #253-Microsoft Mon Dec 31 17:49:00 PST 2018
@0x5c

This comment has been minimized.

Copy link
Author

commented Jun 21, 2019

Some change between 1.0.0 and 1.0.1 seem to be the cause of the issue.

@0x5c

This comment has been minimized.

Copy link
Author

commented Jun 21, 2019

Culprit: dcdcf1a

Edit:
Called it!
image

@Rapptz Rapptz closed this in b2f247b Jun 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.