-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Audio] Improve Lavalink download/connection exception handling (#2764)
- More errors will be logged to the console with clearer messages when something goes wrong - Downloading the Lavalink Jar will abort after 5 failed attempts. The connect task will also abort if an unhandled exception occurs whilst downloading or connecting to Lavalink. After this occurs, instead of responding "Connection to Lavalink has not yet been established" to commands, the bot will respond "Connection to Lavalink has failed". This has no effect on other commands which don't involve connecting to Lavalink (e.g. settings commands). - Logs this message when Lavalink jar is successfully downloaded: `Successfully downloaded Lavalink.jar (<x> bytes written)` - Uses [`tqdm`](https://github.com/tqdm/tqdm/) to display a progress bar whilst downloading Lavalink.jar. Signed-off-by: Toby Harradine <[email protected]>
- Loading branch information
Showing
4 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import aiohttp | ||
|
||
|
||
class AudioError(Exception): | ||
"""Base exception for errors in the Audio cog.""" | ||
|
||
|
||
class LavalinkDownloadFailed(AudioError, RuntimeError): | ||
"""Downloading the Lavalink jar failed. | ||
Attributes | ||
---------- | ||
response : aiohttp.ClientResponse | ||
The response from the server to the failed GET request. | ||
should_retry : bool | ||
Whether or not the Audio cog should retry downloading the jar. | ||
""" | ||
|
||
def __init__(self, *args, response: aiohttp.ClientResponse, should_retry: bool = False): | ||
super().__init__(*args) | ||
self.response = response | ||
self.should_retry = should_retry | ||
|
||
def __repr__(self) -> str: | ||
str_args = [*map(str, self.args), self._response_repr()] | ||
return f"LavalinkDownloadFailed({', '.join(str_args)}" | ||
|
||
def __str__(self) -> str: | ||
return f"{super().__str__()} {self._response_repr()}" | ||
|
||
def _response_repr(self) -> str: | ||
return f"[{self.response.status} {self.response.reason}]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters